Skip to content

Commit f3bbacc

Browse files
franklywatsonUlyanaAndrukhivsisyphusSmiling
authored
Crescendo updates for Rosetta (#63)
* Updated go version, flow-go, crypto packages, removed relic * Updated localnet configs, fixed localnet integration test * Updated integration test * Removed unnecessary comments * Returned back staticcheck for lint, updated const json formatting * Updated formatting for localnet_const * Updated flow-go to v0.35.8 * Fixed payload hash calculating * Added data folder removing before rosetta server build * Updated events fields parsing for indexing * Added previewnet configs for rosetta, disabled outdated canary network * Updated parsing cadence values according to version 1.0 * Added previewnet config for rosetta * Updated localnet integration test * Updated scripts to Cadence 1.0 * Updated basic-transfer transaction to Cadence 1.0 * Added previewnet integration test, updated templates for Cadence scripts to 1.0 * Added previewnet-integration-test command to makefile * Removed unused imports for previewnwt integration test, updated command for deploying contract * Updated according to comment * Updated according to suggested comments * Removed unused import from test, updated cmd formatting * Updated according to comment, removed unnecessary temporary convertExecutionResultV5 * Updated scripts for proxy contract according to comments * First pass at C1.0 upgrade * Remove canary net and added previewnet * Remove canary net and added previewnet * Update imports * Update imports Update destroy() to use Burner.burn() callback * Redundant * Update script/cadence/contracts/FlowColdStorageProxy.cdc Co-authored-by: Giovanni Sanchez <[email protected]> * Added entitlement to limit risks of using Account object * Added entitlement constraint * Revert entitlement, should be in tx * Update script/cadence/contracts/FlowColdStorageProxy.cdc Co-authored-by: Giovanni Sanchez <[email protected]> * Update script/cadence/transactions/basic-transfer.cdc Co-authored-by: Giovanni Sanchez <[email protected]> * Update script/cadence/transactions/proxy-to-flow-transfer.cdc Co-authored-by: Giovanni Sanchez <[email protected]> * Update script/cadence/transactions/proxy-to-flow-transfer.cdc Co-authored-by: Giovanni Sanchez <[email protected]> * Update script/cadence/transactions/proxy-to-flow-transfer.cdc Co-authored-by: Giovanni Sanchez <[email protected]> * Update script/cadence/transactions/proxy-transfer.cdc Co-authored-by: Giovanni Sanchez <[email protected]> * Corrected for C1.0 * Removed canary net and added Previewnet * Updated dependencies and fixed method change from cadence.event.GetFields() to cadence.event.FieldsMappedByName * Made contents of script.go consistent with other Cadence 1.0 script changes Added missing entitlements * Added links to actually used Cadence transactions * Cadence 1.0 fixes * More C1.0 fixes * More C1.0 fixes * Fix imports * Added logging * Added logging * Add PN to conf * Update contract addresses for PN * Update contract addresses for PN * Fix imports * Update script/cadence/scripts/get-public-key.cdc Co-authored-by: Giovanni Sanchez <[email protected]> * Update script/cadence/scripts/get-revoke-status.cdc Co-authored-by: Giovanni Sanchez <[email protected]> * Simplified per suggestion * Updates for PN testing * Tidyup after testing --------- Co-authored-by: UlyanaAndrukhiv <[email protected]> Co-authored-by: Giovanni Sanchez <[email protected]>
1 parent 37cb126 commit f3bbacc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2893
-1345
lines changed

Makefile

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22

33
all: build
44

5-
relic:
6-
./environ/build-relic.py
7-
85
go-build:
9-
go build -tags relic -o server cmd/server/server.go
6+
go build -o server cmd/server/server.go
107

11-
build: relic go-build
8+
build: go-build
129

1310
deps:
1411
go mod download -x
1512

1613
lint:
1714
@go mod tidy
18-
@staticcheck -tags relic ./...
15+
@staticcheck ./...
1916

2017
proto:
2118
@echo ">> Generating model/model.pb.go"
@@ -29,4 +26,7 @@ integration-test-cleanup:
2926
rm -rf flow-go
3027

3128
integration-test:
32-
python3 integration_test.py
29+
python3 integration_test.py
30+
31+
previewnet-integration-test:
32+
python3 previewnet_integration_test.py

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ config file:
358358
mode. During offline mode, only certain Rosetta API endpoints are
359359
functional.
360360

361-
* `network: "mainnet" | "testnet" | "canary" | "localnet"`
361+
* `network: "mainnet" | "testnet" | "previewnet" | "localnet"`
362362

363363
* This defines the specific Flow chain that is being used.
364364

@@ -613,7 +613,8 @@ transaction(sender: Address, receiver: Address, amount: UFix64, nonce: Int64, si
613613
    execute {
614614
        // Get a reference to the sender's FlowColdStorageProxy Vault.
615615
        let acct = getAccount(sender)
616-
        let vault = acct.getCapability(FlowColdStorageProxyVault.VaultCapabilityPublicPath).borrow<&FlowColdStorageProxy.Vault>()!
616+
        let vault = acct.capabilities.borrow<&{FlowColdStorageProxy.Vault}>(FlowColdStorageProxy.VaultCapabilityPublicPath)!
617+
617618
618619
        // Transfer tokens to the receiver.
619620
        vault.transfer(receiver: receiver, amount: amount, nonce: nonce, sig: sig.decodeHex())
@@ -1621,8 +1622,7 @@ transaction(receiver: Address, amount: UFix64) {
16211622
}
16221623
execute {
16231624
let receiver = getAccount(receiver)
1624-
.getCapability(/public/flowTokenReceiver)
1625-
.borrow<&{FungibleToken.Receiver}>()!
1625+
.capabilities.borrow<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)!
16261626
receiver.deposit(from: <-self.xfer)
16271627
}
16281628
}

access/access.go

+24-3
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ import (
77
"crypto/x509"
88
"encoding/hex"
99
"fmt"
10-
"go.opentelemetry.io/otel/attribute"
11-
"go.opentelemetry.io/otel/metric"
1210
"math/rand"
1311
"strconv"
1412
"strings"
1513
"time"
1614

15+
"go.opentelemetry.io/otel/attribute"
16+
"go.opentelemetry.io/otel/metric"
17+
1718
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
1819
libp2ptls "github.com/libp2p/go-libp2p/p2p/security/tls"
1920
"github.com/onflow/cadence"
2021
jsoncdc "github.com/onflow/cadence/encoding/json"
2122
"github.com/onflow/cadence/runtime/common"
22-
"github.com/onflow/flow-go/crypto"
23+
"github.com/onflow/crypto"
2324
"github.com/onflow/flow-go/network/p2p/keyutils"
2425
"github.com/onflow/flow/protobuf/go/flow/access"
2526
"github.com/onflow/flow/protobuf/go/flow/entities"
@@ -88,6 +89,7 @@ func (c Client) Account(ctx context.Context, addr []byte) (*entities.Account, er
8889
trace.EndSpanErr(span, err)
8990
return nil, err
9091
}
92+
log.Debugf("AccessAPI.Account(%a): %r", addr, resp.Account)
9193
trace.EndSpanOk(span)
9294
return resp.Account, nil
9395
}
@@ -114,6 +116,7 @@ func (c Client) AccountAtHeight(ctx context.Context, addr []byte, height uint64)
114116
trace.EndSpanErr(span, err)
115117
return nil, err
116118
}
119+
log.Debugf("AccessAPI.AccountAtHeight(%a): %r", addr, resp.Account)
117120
trace.EndSpanOk(span)
118121
return resp.Account, nil
119122
}
@@ -134,6 +137,7 @@ func (c Client) BlockByHeight(ctx context.Context, height uint64) (*entities.Blo
134137
trace.EndSpanErr(span, err)
135138
return nil, err
136139
}
140+
log.Debugf("AccessAPI.BlockByHeight(%a): %b", height, resp.Block)
137141
trace.EndSpanOk(span)
138142
return resp.Block, nil
139143
}
@@ -154,6 +158,7 @@ func (c Client) BlockByID(ctx context.Context, blockID []byte) (*entities.Block,
154158
trace.EndSpanErr(span, err)
155159
return nil, err
156160
}
161+
log.Debugf("AccessAPI.BlockByID(%a): %b", blockID, resp.Block)
157162
trace.EndSpanOk(span)
158163
return resp.Block, nil
159164
}
@@ -180,7 +185,9 @@ func (c Client) BlockEvents(ctx context.Context, blockID []byte, typ string) ([]
180185
trace.EndSpanErr(span, err)
181186
return nil, err
182187
}
188+
log.Debugf("AccessAPI.BlockEvents(): %a\n%b", blockID, resp.Results)
183189
trace.EndSpanOk(span)
190+
184191
return resp.Results[0].Events, nil
185192
}
186193

@@ -199,6 +206,7 @@ func (c Client) BlockHeaderByHeight(ctx context.Context, height uint64) (*entiti
199206
trace.EndSpanErr(span, err)
200207
return nil, err
201208
}
209+
log.Debugf("AccessAPI.BlockHeaderByHeight(%a): %b", height, resp.Block)
202210
trace.EndSpanOk(span)
203211
return resp.Block, nil
204212
}
@@ -218,6 +226,7 @@ func (c Client) BlockHeaderByID(ctx context.Context, blockID []byte) (*entities.
218226
trace.EndSpanErr(span, err)
219227
return nil, err
220228
}
229+
log.Debugf("AccessAPI.BlockHeaderByID(%a): %b", blockID, resp.Block)
221230
trace.EndSpanOk(span)
222231
return resp.Block, nil
223232
}
@@ -238,6 +247,7 @@ func (c Client) CollectionByID(ctx context.Context, id []byte) (*entities.Collec
238247
trace.EndSpanErr(span, err)
239248
return nil, err
240249
}
250+
log.Debugf("AccessAPI.CollectionByID(%a): %b", id, resp.Collection)
241251
trace.EndSpanOk(span)
242252
return resp.Collection, nil
243253
}
@@ -281,6 +291,7 @@ func (c Client) Execute(ctx context.Context, blockID []byte, script []byte, args
281291
trace.EndSpanErr(span, err)
282292
return nil, err
283293
}
294+
log.Debugf("AccessAPI.Execute(): %a = %b", blockID, val)
284295
trace.EndSpanOk(span)
285296
return val, nil
286297
}
@@ -300,6 +311,7 @@ func (c Client) ExecutionResultForBlockID(ctx context.Context, blockID []byte) (
300311
trace.EndSpanErr(span, err)
301312
return nil, err
302313
}
314+
log.Debugf("AccessAPI.ExecutionResultForBlockID(): %a", resp.ExecutionResult)
303315
trace.EndSpanOk(span)
304316
return resp.ExecutionResult, nil
305317
}
@@ -320,6 +332,8 @@ func (c Client) LatestBlockHeader(ctx context.Context) (*entities.BlockHeader, e
320332
trace.EndSpanErr(span, err)
321333
return nil, err
322334
}
335+
336+
log.Debugf("AccessAPI.LatestBlockHeader(): %b", resp.Block)
323337
trace.EndSpanOk(span)
324338
return resp.Block, nil
325339
}
@@ -340,6 +354,7 @@ func (c Client) LatestFinalizedBlockHeader(ctx context.Context) (*entities.Block
340354
trace.EndSpanErr(span, err)
341355
return nil, err
342356
}
357+
log.Debugf("AccessAPI.LatestFinalizedBlockHeader(): %b", resp.Block)
343358
trace.EndSpanOk(span)
344359
return resp.Block, nil
345360
}
@@ -371,6 +386,7 @@ func (c *Client) SendTransaction(ctx context.Context, txn *entities.Transaction)
371386
trace.EndSpanErr(span, err)
372387
return nil, err
373388
}
389+
log.Debugf("AccessAPI.SendTransaction(): %t, %b", txn, resp.Id)
374390
trace.EndSpanOk(span)
375391
return resp.Id, nil
376392
}
@@ -396,6 +412,7 @@ func (c Client) Transaction(ctx context.Context, hash []byte) (*entities.Transac
396412
trace.EndSpanErr(span, err)
397413
return nil, err
398414
}
415+
log.Debugf("AccessAPI.Transaction(%a): %b", hash, resp.Transaction)
399416
trace.EndSpanOk(span)
400417
return resp.Transaction, nil
401418
}
@@ -419,6 +436,7 @@ func (c Client) TransactionResult(ctx context.Context, blockID []byte, txnIndex
419436
return nil, err
420437
}
421438
trace.EndSpanOk(span)
439+
log.Debugf("AccessAPI.TransactionResult(%i): %r", blockID, resp)
422440
return resp, nil
423441
}
424442

@@ -446,6 +464,7 @@ func (c Client) TransactionResultByHash(ctx context.Context, hash []byte) (*acce
446464
return nil, err
447465
}
448466
trace.EndSpanOk(span)
467+
log.Debugf("AccessAPI.TransactionResultByHash(): %a", hash)
449468
return resp, nil
450469
}
451470

@@ -467,6 +486,7 @@ func (c Client) TransactionResultsByBlockID(ctx context.Context, blockID []byte)
467486
return nil, err
468487
}
469488
trace.EndSpanOk(span)
489+
log.Debugf("AccessAPI.TransactionResultsByBlockID(): %a", blockID)
470490
return resp.TransactionResults, nil
471491
}
472492

@@ -489,6 +509,7 @@ func (c Client) TransactionsByBlockID(ctx context.Context, blockID []byte) ([]*e
489509
return nil, err
490510
}
491511
trace.EndSpanOk(span)
512+
log.Debugf("AccessAPI.TransactionsByBlockID(): %a", blockID)
492513
return resp.Transactions, nil
493514
}
494515

api/account_service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (s *Server) getSequenceNumber(ctx context.Context, addr []byte, block *mode
161161
if err != nil {
162162
return 0, err
163163
}
164-
nonce, ok := resp.ToGoValue().(int64)
164+
nonce, ok := resp.(cadence.Int64)
165165
if !ok {
166166
return 0, fmt.Errorf("failed to convert get_proxy_nonce result to int64")
167167
}

api/call_service.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (s *Server) accountPublicKeys(ctx context.Context, params map[string]interf
132132
if err != nil {
133133
return nil, handleExecutionErr(err, "execute get_proxy_public_key")
134134
}
135-
rawKey, ok := resp.ToGoValue().(string)
135+
rawKey, ok := resp.(cadence.String)
136136
if !ok {
137137
return nil, wrapErrorf(
138138
errInternal, "failed to convert get_proxy_public_key result to string",
@@ -146,7 +146,7 @@ func (s *Server) accountPublicKeys(ctx context.Context, params map[string]interf
146146
len(keys),
147147
)
148148
}
149-
pub, err := hex.DecodeString(rawKey)
149+
pub, err := hex.DecodeString(string(rawKey))
150150
if err != nil {
151151
return nil, wrapErrorf(
152152
errInternal,
@@ -246,14 +246,15 @@ func (s *Server) getOnchainData(ctx context.Context, addr []byte, block []byte)
246246
if err != nil {
247247
return nil, handleExecutionErr(err, "execute "+scriptName)
248248
}
249-
fields, ok := resp.ToGoValue().([]interface{})
249+
structValue, ok := resp.(cadence.Struct)
250250
if !ok {
251251
return nil, wrapErrorf(
252252
errInternal,
253-
"failed to convert %s result to Go slice",
253+
"failed to convert %s result to array",
254254
scriptName,
255255
)
256256
}
257+
fields := cadence.FieldsMappedByName(structValue)
257258
if len(fields) != 3 {
258259
return nil, wrapErrorf(
259260
errInternal,
@@ -262,30 +263,33 @@ func (s *Server) getOnchainData(ctx context.Context, addr []byte, block []byte)
262263
)
263264
}
264265
onchain := &onchainData{}
265-
onchain.DefaultBalance, ok = fields[0].(uint64)
266+
defaultBalance, ok := fields["default_balance"].(cadence.UFix64)
266267
if !ok {
267268
return nil, wrapErrorf(
268269
errInternal,
269270
"expected first field of the %s result to be uint64: got %T",
270-
scriptName, fields[0],
271+
scriptName, fields["default_balance"],
271272
)
272273
}
273-
onchain.IsProxy, ok = fields[1].(bool)
274+
onchain.DefaultBalance = uint64(defaultBalance)
275+
isProxy, ok := fields["is_proxy"].(cadence.Bool)
274276
if !ok {
275277
return nil, wrapErrorf(
276278
errInternal,
277279
"expected second field of the %s result to be bool: got %T",
278-
scriptName, fields[1],
280+
scriptName, fields["is_proxy"],
279281
)
280282
}
281-
onchain.ProxyBalance, ok = fields[2].(uint64)
283+
onchain.IsProxy = bool(isProxy)
284+
proxyBalance, ok := fields["proxy_balance"].(cadence.UFix64)
282285
if !ok {
283286
return nil, wrapErrorf(
284287
errInternal,
285288
"expected third field of the %s result to be uint64: got %T",
286-
scriptName, fields[2],
289+
scriptName, fields["proxy_balance"],
287290
)
288291
}
292+
onchain.ProxyBalance = uint64(proxyBalance)
289293
return onchain, nil
290294
}
291295

0 commit comments

Comments
 (0)