Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bring Rosetta dependencies up to date #261

Merged
merged 13 commits into from
Dec 28, 2021
Merged
13 changes: 13 additions & 0 deletions .changelog/261.breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Bring Rosetta dependencies up to date

We're updating our Rosetta dependencies, including the
Go SDK, the CLI, and along with those, the Rosetta API
specifications.

- Rosetta CLI: 0.4.0 -> 0.7.3
- Rosetta Go SDK: 0.3.3 -> 0.7.2
- Rosetta API: 1.4.1 -> 1.4.10

Updating the Rosetta API along with its Go SDK is a
significant update and may have introduced breaking
changes.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include common.mk

OASIS_RELEASE := 21.3.5
ROSETTA_CLI_RELEASE := 0.4.0
OASIS_RELEASE := 21.3.7
ROSETTA_CLI_RELEASE := 0.7.3

# Check which tool to use for downloading.
HAVE_WGET := $(shell which wget > /dev/null && echo 1)
Expand Down
9 changes: 3 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ go 1.15
replace github.com/tendermint/tendermint => github.com/oasisprotocol/tendermint v0.34.9-oasis2

require (
github.com/coinbase/rosetta-cli v0.4.0
github.com/coinbase/rosetta-sdk-go v0.3.3
github.com/dgraph-io/badger v1.6.2
github.com/ethereum/go-ethereum v1.10.9 // indirect
github.com/coinbase/rosetta-cli v0.7.3
github.com/coinbase/rosetta-sdk-go v0.7.2
github.com/oasisprotocol/ed25519 v0.0.0-20210127160119-f7017427c1ea
github.com/oasisprotocol/oasis-core/go v0.2103.5
github.com/vmihailenco/msgpack/v5 v5.3.4
github.com/oasisprotocol/oasis-core/go v0.2103.7
google.golang.org/grpc v1.41.0
)
182 changes: 54 additions & 128 deletions go.sum

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func NewBlockchainRouter(oasisClient oasis.Client) (http.Handler, error) {
Network: chainID,
},
},
nil,
false,
"",
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -96,6 +99,9 @@ func NewOfflineBlockchainRouter(chainID string) (http.Handler, error) {
Network: chainID,
},
},
nil,
false,
"",
)
if err != nil {
return nil, err
Expand Down
10 changes: 10 additions & 0 deletions services/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,13 @@ func (s *accountAPIService) AccountBalance(

return resp, nil
}

func (s *accountAPIService) AccountCoins(
ctx context.Context,
request *types.AccountCoinsRequest,
) (*types.AccountCoinsResponse, *types.Error) {
// https://www.rosetta-api.org/docs/AccountApi.html#accountcoins
// If your implementation does not support coins (i.e. it is for an account-based blockchain), you do not need to
// implement this endpoint.
return nil, ErrNotImplemented
}
27 changes: 20 additions & 7 deletions services/construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,12 @@ func (s *constructionAPIService) ConstructionDerive(
}

resp := &types.ConstructionDeriveResponse{
Address: StringFromAddress(staking.NewAddress(pk)),
AccountIdentifier: &types.AccountIdentifier{
Address: StringFromAddress(staking.NewAddress(pk)),
SubAccount: nil,
Metadata: nil,
},
Metadata: nil,
}

jr, _ := json.Marshal(resp)
Expand Down Expand Up @@ -312,7 +317,7 @@ func (s *constructionAPIService) ConstructionParse(

var tx transaction.Transaction
var from string
var signers []string
var signers []*types.AccountIdentifier
switch request.Signed {
case true:
var signedTx transaction.SignedTransaction
Expand All @@ -331,7 +336,11 @@ func (s *constructionAPIService) ConstructionParse(
return nil, ErrMalformedValue
}
from = StringFromAddress(staking.NewAddress(signedTx.Signature.PublicKey))
signers = []string{from}
signers = []*types.AccountIdentifier{{
Address: from,
SubAccount: nil,
Metadata: nil,
}}
case false:
var unsignedTx UnsignedTransaction
if err = cbor.Unmarshal(rawTx, &unsignedTx); err != nil {
Expand All @@ -350,7 +359,7 @@ func (s *constructionAPIService) ConstructionParse(
from = unsignedTx.Signer
}

om := newTransactionToOperationMapper(&tx, from, "", []*types.Operation{})
om := newTransactionToOperationMapper(&tx, from, nil, []*types.Operation{})
om.EmitFeeOps()
if err := om.EmitTxOps(); err != nil {
loggerCons.Error("ConstructionParse: malformed transaction",
Expand All @@ -360,8 +369,8 @@ func (s *constructionAPIService) ConstructionParse(
}

resp := &types.ConstructionParseResponse{
Operations: om.Operations(),
Signers: signers,
Operations: om.Operations(),
AccountIdentifierSigners: signers,
Metadata: map[string]interface{}{
NonceKey: tx.Nonce,
},
Expand Down Expand Up @@ -482,7 +491,11 @@ func (s *constructionAPIService) ConstructionPayloads(
UnsignedTransaction: base64.StdEncoding.EncodeToString(utCBOR),
Payloads: []*types.SigningPayload{
{
Address: signWithAddr,
AccountIdentifier: &types.AccountIdentifier{
Address: signWithAddr,
SubAccount: nil,
Metadata: nil,
},
Bytes: txMessage,
SignatureType: types.Ed25519,
},
Expand Down
9 changes: 5 additions & 4 deletions services/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (d *transactionsDecoder) DecodeTx(rawTx []byte, result *results.Result) err
default:
status = OpStatusFailed
}
t2o := newTransactionToOperationMapper(&tx, txSignerAddress, status, rosettaTx.Operations)
t2o := newTransactionToOperationMapper(&tx, txSignerAddress, &status, rosettaTx.Operations)

// If no fee operations were emitted, emit some now.
if !o2t.HasFee() {
Expand Down Expand Up @@ -166,12 +166,13 @@ func appendOp(
amt string,
) []*types.Operation {
opIndex := int64(len(ops))
status := OpStatusOK
op := &types.Operation{
OperationIdentifier: &types.OperationIdentifier{
Index: opIndex,
},
Type: kind,
Status: OpStatusOK,
Status: &status,
Account: &types.AccountIdentifier{
Address: acct,
SubAccount: subacct,
Expand Down Expand Up @@ -605,7 +606,7 @@ func newOperationToTransactionMapper(ops []*types.Operation) *operationToTransac
type transactionToOperationMapper struct {
tx *transaction.Transaction
txSignerAddress string
status string
status *string

ops []*types.Operation
}
Expand Down Expand Up @@ -855,7 +856,7 @@ func (m *transactionToOperationMapper) EmitTxOps() error {
func newTransactionToOperationMapper(
tx *transaction.Transaction,
txSignerAddress string,
status string,
status *string,
ops []*types.Operation,
) *transactionToOperationMapper {
return &transactionToOperationMapper{
Expand Down
140 changes: 23 additions & 117 deletions tests/check-prep/main.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
package main

import (
"bytes"
"encoding/hex"
"io/ioutil"
"os"
"path"

"github.com/coinbase/rosetta-cli/configuration"
"github.com/coinbase/rosetta-sdk-go/keys"
"github.com/coinbase/rosetta-sdk-go/storage/modules"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/dgraph-io/badger"
"github.com/oasisprotocol/oasis-core/go/staking/api"
"github.com/vmihailenco/msgpack/v5"

"github.com/oasisprotocol/oasis-core-rosetta-gateway/services"
"github.com/oasisprotocol/oasis-core-rosetta-gateway/tests/common"
)

func storageEncode(v interface{}) []byte {
var buf bytes.Buffer
enc := msgpack.GetEncoder()
enc.Reset(&buf)
enc.SetCustomStructTag("json")
if err := enc.Encode(v); err != nil {
panic(err)
}
msgpack.PutEncoder(enc)
return buf.Bytes()
}

func getRosettaConfig(ni *types.NetworkIdentifier) *configuration.Configuration {
// Create a configuration file for the local testnet.
config := configuration.DefaultConfiguration()
Expand All @@ -37,63 +20,31 @@ func getRosettaConfig(ni *types.NetworkIdentifier) *configuration.Configuration

config.DataDirectory = "/tmp/rosetta-cli-oasistests"

config.Construction.Currency = services.OasisCurrency
config.Construction.MaximumFee = "0"
config.Construction.CurveType = types.Edwards25519
config.Construction.Scenario = []*types.Operation{
{
OperationIdentifier: &types.OperationIdentifier{
Index: 0,
},
Type: services.OpTransfer,
Account: &types.AccountIdentifier{
Address: "{{ SENDER }}",
},
Amount: &types.Amount{
Value: "-100",
Currency: services.OasisCurrency,
},
},
{
OperationIdentifier: &types.OperationIdentifier{
Index: 1,
},
Type: services.OpTransfer,
Account: &types.AccountIdentifier{
Address: services.StringFromAddress(api.FeeAccumulatorAddress),
},
Amount: &types.Amount{
Value: "100",
Currency: services.OasisCurrency,
},
},
{
OperationIdentifier: &types.OperationIdentifier{
Index: 2,
},
Type: services.OpTransfer,
Account: &types.AccountIdentifier{
Address: "{{ SENDER }}",
},
Amount: &types.Amount{
Value: "{{ SENDER_VALUE }}",
Currency: services.OasisCurrency,
testEntityAddress, testEntityKeyPair := common.TestEntity()
config.Construction = &configuration.ConstructionConfiguration{
PrefundedAccounts: []*modules.PrefundedAccount{
{
PrivateKeyHex: hex.EncodeToString(testEntityKeyPair.PrivateKey),
AccountIdentifier: &types.AccountIdentifier{
Address: testEntityAddress,
SubAccount: nil,
Metadata: nil,
},
CurveType: types.Edwards25519,
Currency: services.OasisCurrency,
},
},
{
OperationIdentifier: &types.OperationIdentifier{
Index: 3,
},
Type: services.OpTransfer,
Account: &types.AccountIdentifier{
Address: "{{ RECIPIENT }}",
},
Amount: &types.Amount{
Value: "{{ RECIPIENT_VALUE }}",
Currency: services.OasisCurrency,
},
ConstructorDSLFile: "oasis.ros",
EndConditions: map[string]int{
"transfer": 42,
},
}
dataHistoricalBalanceEnabled := true
config.Data.HistoricalBalanceEnabled = &dataHistoricalBalanceEnabled
dataEndTip := true
config.Data.EndConditions = &configuration.DataEndConditions{
Tip: &dataEndTip,
}

return config
}
Expand All @@ -107,49 +58,4 @@ func main() {
if err = ioutil.WriteFile("rosetta-cli-config.json", []byte(common.DumpJSON(config)), 0o600); err != nil {
panic(err)
}

// Create an account for construction tests.
testEntityAddress, testEntityKeyPair := common.TestEntity()

constructionStorePath := path.Join(config.DataDirectory, "check-construction", types.Hash(config.Network))
if err = os.MkdirAll(constructionStorePath, 0o777); err != nil {
panic(err)
}
db, err := badger.Open(badger.DefaultOptions(constructionStorePath))
if err != nil {
panic(err)
}
if err := db.Update(func(txn *badger.Txn) error {
if err := txn.Set([]byte("key/"+testEntityAddress), storageEncode(&struct {
Address string `json:"address"`
KeyPair *keys.KeyPair `json:"keypair"`
}{
Address: testEntityAddress,
KeyPair: testEntityKeyPair,
})); err != nil {
panic(err)
}
testEntityAccountIdentifier := types.AccountIdentifier{Address: testEntityAddress}
if err := txn.Set(
[]byte("balance/"+types.Hash(&testEntityAccountIdentifier)+"/"+types.Hash(services.OasisCurrency)),
storageEncode(
&struct {
Account *types.AccountIdentifier `json:"account"`
Amount *types.Amount `json:"amount"`
Block *types.BlockIdentifier `json:"block"`
}{
Account: &testEntityAccountIdentifier,
Amount: common.TestEntityAmount,
},
),
); err != nil {
panic(err)
}
return nil
}); err != nil {
panic(err)
}
if err := db.Close(); err != nil {
panic(err)
}
}
14 changes: 9 additions & 5 deletions tests/construction-signing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func main() { //nolint:funlen
panic(re)
}
fmt.Println("unsigned operations", common.DumpJSON(r4p.Operations))
fmt.Println("unsigned signers", common.DumpJSON(r4p.Signers))
fmt.Println("unsigned signers", common.DumpJSON(r4p.AccountIdentifierSigners))
fmt.Println("unsigned metadata", common.DumpJSON(r4p.Metadata))
r4pRef := &types.ConstructionParseResponse{
Operations: ops,
Expand All @@ -117,7 +117,7 @@ func main() { //nolint:funlen

sigs := make([]*types.Signature, 0, len(r4.Payloads))
for i, sp := range r4.Payloads {
if sp.Address != testEntityAddress {
if sp.AccountIdentifier.Address != testEntityAddress {
panic(i)
}
sig, err2 := rs.Sign(sp, sp.SignatureType)
Expand Down Expand Up @@ -152,12 +152,16 @@ func main() { //nolint:funlen
panic(re)
}
fmt.Println("signed operations", common.DumpJSON(r5p.Operations))
fmt.Println("signed signers", common.DumpJSON(r5p.Signers))
fmt.Println("signed signers", common.DumpJSON(r5p.AccountIdentifierSigners))
fmt.Println("signed metadata", common.DumpJSON(r5p.Metadata))
r5pRef := &types.ConstructionParseResponse{
Operations: ops,
Signers: []string{testEntityAddress},
Metadata: r3.Metadata,
AccountIdentifierSigners: []*types.AccountIdentifier{{
Address: testEntityAddress,
SubAccount: nil,
Metadata: nil,
}},
Metadata: r3.Metadata,
}
if !reflect.DeepEqual(r5p, r5pRef) {
fmt.Println("signed transaction parsed", common.DumpJSON(r5p))
Expand Down
Loading