Skip to content

Commit

Permalink
fix parsing of asset strings in contractevents
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirms committed Sep 14, 2023
1 parent 38dc8aa commit 377dbf6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
4 changes: 2 additions & 2 deletions support/contractevents/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func parseCanonicalAsset(assetStr string) (*xdr.Asset, error) {
Ed25519: issuerKey.Ed25519,
})

if len(rawCode) == 4 {
if len(rawCode) <= 4 {

Check failure on line 176 in support/contractevents/event.go

View workflow job for this annotation

GitHub Actions / golangci

mnd: Magic number: 4, in <condition> detected (gomnd)
code := [4]byte{}
copy(code[:], rawCode[:])

Expand All @@ -182,7 +182,7 @@ func parseCanonicalAsset(assetStr string) (*xdr.Asset, error) {
AssetCode: xdr.AssetCode4(code),
Issuer: accountId,
}
} else if len(rawCode) == 12 {
} else if len(rawCode) <= 12 {

Check failure on line 185 in support/contractevents/event.go

View workflow job for this annotation

GitHub Actions / golangci

mnd: Magic number: 12, in <condition> detected (gomnd)
code := [12]byte{}
copy(code[:], rawCode[:])

Expand Down
18 changes: 2 additions & 16 deletions support/contractevents/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,8 @@ func makeAsset(asset xdr.Asset) xdr.ScVal {
panic(err)
}

case xdr.AssetTypeAssetTypeCreditAlphanum4:
_, err := xdr.Marshal(buffer, asset.AlphaNum4.AssetCode)
if err != nil {
panic(err)
}
buffer.WriteString(":")
buffer.WriteString(asset.AlphaNum4.Issuer.Address())

case xdr.AssetTypeAssetTypeCreditAlphanum12:
_, err := xdr.Marshal(buffer, asset.AlphaNum12.AssetCode)
if err != nil {
panic(err)
}
buffer.WriteString(":")
buffer.WriteString(asset.AlphaNum12.Issuer.Address())

case xdr.AssetTypeAssetTypeCreditAlphanum4, xdr.AssetTypeAssetTypeCreditAlphanum12:
buffer.WriteString(asset.GetCode() + ":" + asset.GetIssuer())
default:
panic("unexpected asset type")
}
Expand Down

0 comments on commit 377dbf6

Please sign in to comment.