Skip to content

Commit 41d1988

Browse files
Fix Cadence errors and remove noisy logging (#64)
* Fix out of sync Cadence and remove noisy logging * Fix out of sync Cadence and remove noisy logging * Tune logging to only dumping script content * Fixed typo in Cadence * Fixed typo in Cadence * Commented out FlowColdStorage import and logic since the contract is not yet deployed to mainnet Added missing optional * Update script/script.go Co-authored-by: Giovanni Sanchez <[email protected]> * Add comment to clarify why code is commented out * Add note to clarify why code is commented out --------- Co-authored-by: Giovanni Sanchez <[email protected]>
1 parent 8548dd0 commit 41d1988

File tree

3 files changed

+30
-38
lines changed

3 files changed

+30
-38
lines changed

access/access.go

+2-18
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ func (c Client) Account(ctx context.Context, addr []byte) (*entities.Account, er
8989
trace.EndSpanErr(span, err)
9090
return nil, err
9191
}
92-
log.Debugf("AccessAPI.Account(%a): %r", addr, resp.Account)
9392
trace.EndSpanOk(span)
9493
return resp.Account, nil
9594
}
@@ -116,7 +115,6 @@ func (c Client) AccountAtHeight(ctx context.Context, addr []byte, height uint64)
116115
trace.EndSpanErr(span, err)
117116
return nil, err
118117
}
119-
log.Debugf("AccessAPI.AccountAtHeight(%a): %r", addr, resp.Account)
120118
trace.EndSpanOk(span)
121119
return resp.Account, nil
122120
}
@@ -137,7 +135,6 @@ func (c Client) BlockByHeight(ctx context.Context, height uint64) (*entities.Blo
137135
trace.EndSpanErr(span, err)
138136
return nil, err
139137
}
140-
log.Debugf("AccessAPI.BlockByHeight(%a): %b", height, resp.Block)
141138
trace.EndSpanOk(span)
142139
return resp.Block, nil
143140
}
@@ -158,7 +155,6 @@ func (c Client) BlockByID(ctx context.Context, blockID []byte) (*entities.Block,
158155
trace.EndSpanErr(span, err)
159156
return nil, err
160157
}
161-
log.Debugf("AccessAPI.BlockByID(%a): %b", blockID, resp.Block)
162158
trace.EndSpanOk(span)
163159
return resp.Block, nil
164160
}
@@ -185,7 +181,6 @@ func (c Client) BlockEvents(ctx context.Context, blockID []byte, typ string) ([]
185181
trace.EndSpanErr(span, err)
186182
return nil, err
187183
}
188-
log.Debugf("AccessAPI.BlockEvents(): %a\n%b", blockID, resp.Results)
189184
trace.EndSpanOk(span)
190185

191186
return resp.Results[0].Events, nil
@@ -206,7 +201,6 @@ func (c Client) BlockHeaderByHeight(ctx context.Context, height uint64) (*entiti
206201
trace.EndSpanErr(span, err)
207202
return nil, err
208203
}
209-
log.Debugf("AccessAPI.BlockHeaderByHeight(%a): %b", height, resp.Block)
210204
trace.EndSpanOk(span)
211205
return resp.Block, nil
212206
}
@@ -226,7 +220,6 @@ func (c Client) BlockHeaderByID(ctx context.Context, blockID []byte) (*entities.
226220
trace.EndSpanErr(span, err)
227221
return nil, err
228222
}
229-
log.Debugf("AccessAPI.BlockHeaderByID(%a): %b", blockID, resp.Block)
230223
trace.EndSpanOk(span)
231224
return resp.Block, nil
232225
}
@@ -247,7 +240,6 @@ func (c Client) CollectionByID(ctx context.Context, id []byte) (*entities.Collec
247240
trace.EndSpanErr(span, err)
248241
return nil, err
249242
}
250-
log.Debugf("AccessAPI.CollectionByID(%a): %b", id, resp.Collection)
251243
trace.EndSpanOk(span)
252244
return resp.Collection, nil
253245
}
@@ -269,6 +261,7 @@ func (c Client) Execute(ctx context.Context, blockID []byte, script []byte, args
269261
cargs[i] = val
270262
}
271263
ctx, cancel := context.WithTimeout(ctx, defaultTimeout)
264+
log.Debugf("AccessAPI.Execute(): %s", string(script))
272265
resp, err := c.client.ExecuteScriptAtBlockID(
273266
ctx,
274267
&access.ExecuteScriptAtBlockIDRequest{
@@ -291,7 +284,6 @@ func (c Client) Execute(ctx context.Context, blockID []byte, script []byte, args
291284
trace.EndSpanErr(span, err)
292285
return nil, err
293286
}
294-
log.Debugf("AccessAPI.Execute(): %a = %b", blockID, val)
295287
trace.EndSpanOk(span)
296288
return val, nil
297289
}
@@ -311,7 +303,6 @@ func (c Client) ExecutionResultForBlockID(ctx context.Context, blockID []byte) (
311303
trace.EndSpanErr(span, err)
312304
return nil, err
313305
}
314-
log.Debugf("AccessAPI.ExecutionResultForBlockID(): %a", resp.ExecutionResult)
315306
trace.EndSpanOk(span)
316307
return resp.ExecutionResult, nil
317308
}
@@ -333,7 +324,6 @@ func (c Client) LatestBlockHeader(ctx context.Context) (*entities.BlockHeader, e
333324
return nil, err
334325
}
335326

336-
log.Debugf("AccessAPI.LatestBlockHeader(): %b", resp.Block)
337327
trace.EndSpanOk(span)
338328
return resp.Block, nil
339329
}
@@ -354,7 +344,6 @@ func (c Client) LatestFinalizedBlockHeader(ctx context.Context) (*entities.Block
354344
trace.EndSpanErr(span, err)
355345
return nil, err
356346
}
357-
log.Debugf("AccessAPI.LatestFinalizedBlockHeader(): %b", resp.Block)
358347
trace.EndSpanOk(span)
359348
return resp.Block, nil
360349
}
@@ -386,7 +375,7 @@ func (c *Client) SendTransaction(ctx context.Context, txn *entities.Transaction)
386375
trace.EndSpanErr(span, err)
387376
return nil, err
388377
}
389-
log.Debugf("AccessAPI.SendTransaction(): %t, %b", txn, resp.Id)
378+
log.Debugf("AccessAPI.SendTransaction(): %s", string(txn.Script))
390379
trace.EndSpanOk(span)
391380
return resp.Id, nil
392381
}
@@ -412,7 +401,6 @@ func (c Client) Transaction(ctx context.Context, hash []byte) (*entities.Transac
412401
trace.EndSpanErr(span, err)
413402
return nil, err
414403
}
415-
log.Debugf("AccessAPI.Transaction(%a): %b", hash, resp.Transaction)
416404
trace.EndSpanOk(span)
417405
return resp.Transaction, nil
418406
}
@@ -436,7 +424,6 @@ func (c Client) TransactionResult(ctx context.Context, blockID []byte, txnIndex
436424
return nil, err
437425
}
438426
trace.EndSpanOk(span)
439-
log.Debugf("AccessAPI.TransactionResult(%i): %r", blockID, resp)
440427
return resp, nil
441428
}
442429

@@ -464,7 +451,6 @@ func (c Client) TransactionResultByHash(ctx context.Context, hash []byte) (*acce
464451
return nil, err
465452
}
466453
trace.EndSpanOk(span)
467-
log.Debugf("AccessAPI.TransactionResultByHash(): %a", hash)
468454
return resp, nil
469455
}
470456

@@ -486,7 +472,6 @@ func (c Client) TransactionResultsByBlockID(ctx context.Context, blockID []byte)
486472
return nil, err
487473
}
488474
trace.EndSpanOk(span)
489-
log.Debugf("AccessAPI.TransactionResultsByBlockID(): %a", blockID)
490475
return resp.TransactionResults, nil
491476
}
492477

@@ -509,7 +494,6 @@ func (c Client) TransactionsByBlockID(ctx context.Context, blockID []byte) ([]*e
509494
return nil, err
510495
}
511496
trace.EndSpanOk(span)
512-
log.Debugf("AccessAPI.TransactionsByBlockID(): %a", blockID)
513497
return resp.Transactions, nil
514498
}
515499

script/cadence/scripts/get-balances.cdc

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import FlowColdStorageProxy from 0xProxy
1+
// Commenting out this dependency since no accounts on Mainnet contain this contract. If ColdStorage functionality is
2+
// restored then it's a bridge to cross at that time
3+
//import FlowColdStorageProxy from 0xProxy
4+
25
import FlowToken from 0x0ae53cb6e3f42a79
36
import FungibleToken from 0xee82856bf20e2aa6
47

58
access(all) struct AccountBalances {
6-
pub let default_balance: UFix64
7-
pub let is_proxy: Bool
8-
pub let proxy_balance: UFix64
9+
access(all) let default_balance: UFix64
10+
access(all) let is_proxy: Bool
11+
access(all) let proxy_balance: UFix64
912

1013
init(default_balance: UFix64, is_proxy: Bool, proxy_balance: UFix64) {
1114
self.default_balance = default_balance
@@ -16,14 +19,17 @@ access(all) struct AccountBalances {
1619

1720
access(all) fun main(addr: Address): AccountBalances {
1821
let acct = getAccount(addr)
19-
let balanceRef = acct.capabilities.borrow<&FlowToken.Vault}>(/public/flowTokenBalance)
22+
let balanceRef = acct.capabilities.borrow<&FlowToken.Vault>(/public/flowTokenBalance)!
2023
var is_proxy = false
2124
var proxy_balance = 0.0
22-
let ref = acct.capabilities.borrow<&{FlowColdStorageProxy.Vault}>(FlowColdStorageProxy.VaultCapabilityPublicPath)
23-
if let vault = ref {
24-
is_proxy = true
25-
proxy_balance = vault.getBalance()
26-
}
25+
26+
// Same as for above comment
27+
//let ref = acct.capabilities.borrow<&{FlowColdStorageProxy.Vault}>(FlowColdStorageProxy.VaultCapabilityPublicPath)
28+
//if let vault = ref {
29+
// is_proxy = true
30+
// proxy_balance = vault.getBalance()
31+
//}
32+
2733
return AccountBalances(
2834
default_balance: balanceRef.balance,
2935
is_proxy: is_proxy,

script/script.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ transaction(publicKey: String) {
9090
// returns an account's balances.
9191
//
9292
// The returned balances include the value of the account's default FLOW vault,
93-
// as well as the optional FlowColdStorageProxy vault.
94-
const GetBalances = `import FlowColdStorageProxy from 0x{{.Contracts.FlowColdStorageProxy}}
95-
import FlowToken from 0x{{.Contracts.FlowToken}}
93+
// Jul 2024: The introduction of FlowColdStorageProxy contract was originally intended to be for the
94+
// Coinbase Institution investment featureset. However, this feature was never completed or released to MN
95+
// The current version of Rosetta assumes that all CB accounts contain the contract, which is not the case for
96+
// any account on MN.
97+
// As a result if these scripts/transactions include the import they will error on execution in MN
98+
const GetBalances = `import FlowToken from 0x{{.Contracts.FlowToken}}
9699
import FungibleToken from 0x{{.Contracts.FungibleToken}}
97100
98101
access(all) struct AccountBalances {
@@ -109,15 +112,14 @@ access(all) struct AccountBalances {
109112
110113
access(all) fun main(addr: Address): AccountBalances {
111114
let acct = getAccount(addr)
112-
let balanceRef = acct.getCapability(/public/flowTokenBalance)
113-
.borrow<&FlowToken.Vault{FungibleToken.Balance}>()!
115+
let balanceRef = acct.capabilities.borrow<&FlowToken.Vault>(/public/flowTokenBalance)!
114116
var is_proxy = false
115117
var proxy_balance = 0.0
116-
let ref = acct.getCapability(FlowColdStorageProxy.VaultCapabilityPublicPath).borrow<&FlowColdStorageProxy.Vault>()
117-
if let vault = ref {
118-
is_proxy = true
119-
proxy_balance = vault.getBalance()
120-
}
118+
// let ref = acct.capabilities.borrow<&FlowColdStorageProxy.Vault>(FlowColdStorageProxy.VaultCapabilityPublicPath)
119+
// if let vault = ref {
120+
// is_proxy = true
121+
// proxy_balance = vault.getBalance()
122+
//}
121123
return AccountBalances(
122124
default_balance: balanceRef.balance,
123125
is_proxy: is_proxy,

0 commit comments

Comments
 (0)