Skip to content

Commit

Permalink
Tx metadata validation (#76)
Browse files Browse the repository at this point in the history
* [TX] add metadata validation

* [TX] add empty asset validation
  • Loading branch information
covain authored Jul 5, 2021
1 parent 6d9eaf7 commit 4f45dc1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions types/v1/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ type (
AssetHolder interface {
GetAsset() Asset
}

Validator interface {
Validate() error
}
)

var (
Expand Down Expand Up @@ -190,10 +194,34 @@ func (t *Transfer) GetAsset() Asset {
return t.Asset
}

func (t *Transfer) Validate() error {
if t.Value == "" {
return fmt.Errorf("emtpy transfer value")
}

if t.Asset == "" {
return fmt.Errorf("empty transfer asset")
}

return nil
}

func (cc *ContractCall) GetAsset() Asset {
return cc.Asset
}

func (cc *ContractCall) Validate() error {
if cc.Value == "" {
return fmt.Errorf("empty contract call value")
}

if cc.Asset == "" {
return fmt.Errorf("empty contract call asset")
}

return nil
}

func cleanMemo(memo string) string {
if len(memo) == 0 {
return ""
Expand Down

0 comments on commit 4f45dc1

Please sign in to comment.