Skip to content

Commit

Permalink
associate denoms with cosmos types
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-pure committed Apr 14, 2022
1 parent 60047d1 commit da2f23c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion chain/cosmos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (client *Client) Tx(ctx context.Context, txHash pack.Bytes) (account.Tx, pa
if res.Code != 0 {
return &Tx{}, pack.NewU64(0), fmt.Errorf("tx failed code: %v, log: %v", res.Code, res.RawLog)
}
return &Tx{originalTx: authStdTx, encoder: client.ctx.TxConfig.TxEncoder()}, pack.NewU64(1), nil
return &Tx{originalTx: authStdTx, encoder: client.ctx.TxConfig.TxEncoder(), denom: string(client.opts.CoinDenom)}, pack.NewU64(1), nil
}

// SubmitTx to the Cosmos based network.
Expand Down
20 changes: 14 additions & 6 deletions chain/cosmos/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func (builder txBuilder) BuildTx(ctx context.Context, fromPubKey *id.PubKey, to
txBuilder: txBuilder,
sendMsg: &sendMsg,
memo: string(payload),
denom: string(builder.client.opts.CoinDenom),
}, nil
}

Expand Down Expand Up @@ -219,13 +220,17 @@ func (msg MsgSend) Msg() types.Msg {

// Tx is a tx.Tx wrapper
type Tx struct {
// Always present
originalTx *txTypes.Tx
encoder types.TxEncoder
sendMsg *MsgSend
memo string
signMsg []byte
sigV2 signing.SignatureV2
txBuilder client.TxBuilder
denom string

// Fields only used when constucting with a tx builder
sendMsg *MsgSend
memo string
signMsg []byte
sigV2 signing.SignatureV2
txBuilder client.TxBuilder
}

// From returns the sender of the transaction
Expand Down Expand Up @@ -261,7 +266,10 @@ func (t Tx) Value() pack.U256 {
if t.originalTx != nil {
msgs := t.originalTx.GetBody().Messages
for _, msg := range msgs {
value.AddAssign(pack.NewU64(msg.GetCachedValue().(*bankType.MsgSend).Amount[0].Amount.Uint64()))
amount := msg.GetCachedValue().(*bankType.MsgSend).Amount[0]
if amount.Denom == t.denom {
value.AddAssign(pack.NewU64(amount.Amount.Uint64()))
}
}
} else if t.sendMsg != nil {
value.AddAssign(pack.NewU64(t.sendMsg.Amount.Coins()[0].Amount.Uint64()))
Expand Down

0 comments on commit da2f23c

Please sign in to comment.