Skip to content

Commit

Permalink
add default valueS
Browse files Browse the repository at this point in the history
  • Loading branch information
sahith-narahari committed Nov 10, 2020
1 parent 5b88418 commit a0657f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
13 changes: 9 additions & 4 deletions server/rosetta/services/construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ func (sn SingleNetwork) ConstructionMetadata(ctx context.Context, request *types

res := &types.ConstructionMetadataResponse{
Metadata: map[string]interface{}{
rosetta.AccountNumber: string(accountInfo.GetAccountNumber()),
rosetta.Sequence: string(accountInfo.GetSequence()),
rosetta.AccountNumber: accountInfo.GetAccountNumber(),
rosetta.Sequence: accountInfo.GetSequence(),
rosetta.ChainId: status.NodeInfo.Network,
rosetta.OptionGas: gas,
rosetta.OptionMemo: memo,
Expand Down Expand Up @@ -197,7 +197,7 @@ func (sn SingleNetwork) ConstructionPayloads(ctx context.Context, request *types
return nil, rosetta.ErrInvalidOperation.RosettaError()
}

if request.Operations[0].Type != rosetta.OperationTransfer || request.Operations[1].Type != rosetta.OperationTransfer {
if request.Operations[0].Type != rosetta.OperationSend || request.Operations[1].Type != rosetta.OperationSend {
return nil, rosetta.WrapError(rosetta.ErrInvalidOperation, "the operations are not Transfer").RosettaError()
}

Expand Down Expand Up @@ -270,11 +270,16 @@ func (sn SingleNetwork) ConstructionPreprocess(ctx context.Context, request *typ
memo = ""
}

defaultGas := float64(200000)
gas := request.SuggestedFeeMultiplier
if gas == nil {
gas = &defaultGas
}
var res = &types.ConstructionPreprocessResponse{
Options: map[string]interface{}{
rosetta.OptionAddress: txData.FromAddress,
rosetta.OptionMemo: memo,
rosetta.OptionGas: request.SuggestedFeeMultiplier,
rosetta.OptionGas: gas,
},
}
return res, nil
Expand Down
16 changes: 4 additions & 12 deletions server/rosetta/services/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/cosmos/cosmos-sdk/server/rosetta"
"strconv"
)

type PayloadReqMetadata struct {
Expand All @@ -26,27 +25,20 @@ func GetMetadataFromPayloadReq(req *types.ConstructionPayloadsRequest) (*Payload
if !ok {
return nil, fmt.Errorf("sequence metadata was not provided")
}
seqStr, ok := sequence.(string)
seqNum, ok := sequence.(float64)
if !ok {
return nil, fmt.Errorf("invalid sequence value")
}
seqNum, err := strconv.Atoi(seqStr)
if err != nil {
return nil, fmt.Errorf("error converting sequence num to int")
}

accountNum, ok := req.Metadata[rosetta.AccountNumber]
if !ok {
return nil, fmt.Errorf("account_number metadata was not provided")
}
accStr, ok := accountNum.(string)
accNum, ok := accountNum.(float64)
if !ok {
fmt.Printf("this is type %T", accountNum)
return nil, fmt.Errorf("invalid account_number value")
}
accNum, err := strconv.Atoi(accStr)
if err != nil {
return nil, fmt.Errorf("error converting account num to int")
}

gasNum, ok := req.Metadata[rosetta.OptionGas]
if !ok {
Expand All @@ -59,7 +51,7 @@ func GetMetadataFromPayloadReq(req *types.ConstructionPayloadsRequest) (*Payload

memo, ok := req.Metadata[rosetta.OptionMemo]
if !ok {
return nil, fmt.Errorf("memo metadata was not provided")
memo = ""
}
memoStr, ok := memo.(string)
if !ok {
Expand Down

0 comments on commit a0657f8

Please sign in to comment.