Skip to content

Commit

Permalink
[TX V1] fix panic for emtpy coin
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Bozhytskyi committed May 12, 2021
1 parent c3b3cc3 commit 22aeedd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
4 changes: 4 additions & 0 deletions asset/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func BuildID(coin uint, token string) string {

func FindCoinID(words []string) (uint, error) {
for _, w := range words {
if len(w) == 0 {
return 0, errors.New("empty coin")
}

if w[0] == coinPrefix {
rawCoin := removeFirstChar(w)
coin, err := strconv.Atoi(rawCoin)
Expand Down
40 changes: 20 additions & 20 deletions types/v1/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,18 @@ func (d *Delegation) Clean() {
func (d *Delegation) GetMemo() string {
return d.Memo
}
func (t *Delegation) GetAsset() string {
return t.Asset
func (d *Delegation) GetAsset() string {
return d.Asset
}

func (d *Undelegation) Clean() {
d.Memo = cleanMemo(d.Memo)
func (u *Undelegation) Clean() {
u.Memo = cleanMemo(u.Memo)
}
func (d *Undelegation) GetMemo() string {
return d.Memo
func (u *Undelegation) GetMemo() string {
return u.Memo
}
func (t *Undelegation) GetAsset() string {
return t.Asset
func (u *Undelegation) GetAsset() string {
return u.Asset
}

func (r *Redelegation) Clean() {
Expand All @@ -295,8 +295,8 @@ func (r *Redelegation) Clean() {
func (r *Redelegation) GetMemo() string {
return r.Memo
}
func (t *Redelegation) GetAsset() string {
return t.Asset
func (r *Redelegation) GetAsset() string {
return r.Asset
}

func (cr *ClaimRewards) Clean() {
Expand All @@ -305,22 +305,22 @@ func (cr *ClaimRewards) Clean() {
func (cr *ClaimRewards) GetMemo() string {
return cr.Memo
}
func (t *ClaimRewards) GetAsset() string {
return t.Asset
func (cr *ClaimRewards) GetAsset() string {
return cr.Asset
}

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

func (cr *AnyAction) Clean() {
cr.Memo = cleanMemo(cr.Memo)
func (aa *AnyAction) Clean() {
aa.Memo = cleanMemo(aa.Memo)
}
func (cr *AnyAction) GetMemo() string {
return cr.Memo
func (aa *AnyAction) GetMemo() string {
return aa.Memo
}
func (t *AnyAction) GetAsset() string {
return t.Asset
func (aa *AnyAction) GetAsset() string {
return aa.Asset
}

func cleanMemo(memo string) string {
Expand Down

0 comments on commit 22aeedd

Please sign in to comment.