Skip to content

Commit

Permalink
[TX V1] fixes
Browse files Browse the repository at this point in the history
- support marshalling of ClaimRewards type
- fix contract call related issues
  • Loading branch information
Ivan Bozhytskyi committed May 12, 2021
1 parent ba2c933 commit c3b3cc3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions types/v1/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down
10 changes: 7 additions & 3 deletions types/v1/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand All @@ -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
}
Expand Down

0 comments on commit c3b3cc3

Please sign in to comment.