From 4f45dc18b16d4564243631e0426e51dfa2f6ca9b Mon Sep 17 00:00:00 2001 From: Ivan Bozhytksyi <82358585+ivan-bozhytksyi@users.noreply.github.com> Date: Mon, 5 Jul 2021 10:45:06 +0300 Subject: [PATCH] Tx metadata validation (#76) * [TX] add metadata validation * [TX] add empty asset validation --- types/v1/tx.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/types/v1/tx.go b/types/v1/tx.go index a336188..2d06f75 100644 --- a/types/v1/tx.go +++ b/types/v1/tx.go @@ -132,6 +132,10 @@ type ( AssetHolder interface { GetAsset() Asset } + + Validator interface { + Validate() error + } ) var ( @@ -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 ""