From c3b3cc393f37f97b8c49e02714afc75b77705eca Mon Sep 17 00:00:00 2001 From: Ivan Bozhytskyi Date: Wed, 12 May 2021 16:03:41 +0300 Subject: [PATCH] [TX V1] fixes - support marshalling of ClaimRewards type - fix contract call related issues --- types/v1/marshal.go | 4 ++++ types/v1/tx.go | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/types/v1/marshal.go b/types/v1/marshal.go index 1233858..6b0b5fc 100644 --- a/types/v1/marshal.go +++ b/types/v1/marshal.go @@ -33,6 +33,8 @@ func (t *Tx) UnmarshalJSON(data []byte) error { t.Metadata = new(Delegation) case TxRedelegation: t.Metadata = new(Redelegation) + case TxStakeClaimRewards: + t.Metadata = new(ClaimRewards) default: return errors.New("unsupported tx type") } @@ -61,6 +63,8 @@ func (t *Tx) MarshalJSON() ([]byte, error) { t.Type = TxUndelegation case *Redelegation: t.Type = TxRedelegation + case *ClaimRewards: + t.Type = TxStakeClaimRewards default: return nil, errors.New("unsupported tx metadata") } diff --git a/types/v1/tx.go b/types/v1/tx.go index 6157464..881e864 100644 --- a/types/v1/tx.go +++ b/types/v1/tx.go @@ -165,7 +165,7 @@ type ( ContractCall struct { Asset string `json:"asset"` Input string `json:"input"` - Value string `json:"value"` + Value Amount `json:"value"` } // AnyAction describes all other types @@ -309,6 +309,10 @@ func (t *ClaimRewards) GetAsset() string { return t.Asset } +func (сс *ContractCall) GetAsset() string { + return сс.Asset +} + func (cr *AnyAction) Clean() { cr.Memo = cleanMemo(cr.Memo) } @@ -335,7 +339,7 @@ func cleanMemo(memo string) string { func (t *Tx) GetAddresses() []string { addresses := make([]string, 0) switch t.Metadata.(type) { - case *Transfer, *Delegation, *ContractCall, *AnyAction: + case *Transfer, *Delegation, *ContractCall, *AnyAction, *ClaimRewards: return append(addresses, t.From, t.To) case *Redelegation: metadata := t.Metadata.(*Redelegation) @@ -346,7 +350,7 @@ func (t *Tx) GetAddresses() []string { } func (t *Tx) GetSubscriptionAddresses() ([]string, error) { - coin, err := asset.FindCoinID([]string{t.Metadata.(Asset).GetAsset()}) + coin, _, err := asset.ParseID(t.Metadata.(Asset).GetAsset()) if err != nil { return nil, err }