Fix parsedPayload use as any type for different kind of messages (#1169)
Co-authored-by: walker-16 <agpazos85@gmail.com>
This commit is contained in:
parent
6bbfa7bf23
commit
08c9427606
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/wormhole-foundation/wormhole-explorer/common/client/parser"
|
"github.com/wormhole-foundation/wormhole-explorer/common/client/parser"
|
||||||
"github.com/wormhole-foundation/wormhole-explorer/common/domain"
|
"github.com/wormhole-foundation/wormhole-explorer/common/domain"
|
||||||
sdk "github.com/wormhole-foundation/wormhole/sdk/vaa"
|
sdk "github.com/wormhole-foundation/wormhole/sdk/vaa"
|
||||||
|
@ -128,11 +129,12 @@ func createToken(p *parser.ParseVaaWithStandarizedPropertiesdResponse, emitterCh
|
||||||
|
|
||||||
addressHex, err := domain.DecodeNativeAddressToHex(p.StandardizedProperties.TokenChain, p.StandardizedProperties.TokenAddress)
|
addressHex, err := domain.DecodeNativeAddressToHex(p.StandardizedProperties.TokenChain, p.StandardizedProperties.TokenAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if p.ParsedPayload != nil && p.ParsedPayload.TokenAddress != "" {
|
tokenParsedPayload, err := parseTokenPayload(p.ParsedPayload)
|
||||||
addressHex = p.ParsedPayload.TokenAddress
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cannot decode token with tokenChain [%d] tokenAddress [%s] to hex. %v",
|
||||||
|
p.StandardizedProperties.TokenChain, p.StandardizedProperties.TokenAddress, err)
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("cannot decode token with tokenChain [%d] tokenAddress [%s] to hex",
|
addressHex = *tokenParsedPayload.TokenAddress
|
||||||
p.StandardizedProperties.TokenChain, p.StandardizedProperties.TokenAddress)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,3 +163,28 @@ func createToken(p *parser.ParseVaaWithStandarizedPropertiesdResponse, emitterCh
|
||||||
Amount: n,
|
Amount: n,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseTokenPayload(parsedPayload any) (*tokenParsedPayload, error) {
|
||||||
|
if parsedPayload == nil {
|
||||||
|
return nil, fmt.Errorf("parsedPayload is nil")
|
||||||
|
}
|
||||||
|
var result *tokenParsedPayload
|
||||||
|
err := mapstructure.Decode(parsedPayload, &result)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("parsedPayload can not decode %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.TokenAddress == nil {
|
||||||
|
return nil, fmt.Errorf("tokenAddress in parsedPayload is nil")
|
||||||
|
|
||||||
|
}
|
||||||
|
if result.TokenChain == nil {
|
||||||
|
return nil, fmt.Errorf("tokenChain in parsedPayload is nil")
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type tokenParsedPayload struct {
|
||||||
|
TokenAddress *string `json:"tokenAddress"`
|
||||||
|
TokenChain *int `json:"tokenChain"`
|
||||||
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ require (
|
||||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.14 // indirect
|
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
||||||
|
github.com/mitchellh/mapstructure v1.4.1
|
||||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
|
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
|
||||||
github.com/philhofer/fwd v1.1.2 // indirect
|
github.com/philhofer/fwd v1.1.2 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
|
|
@ -268,6 +268,8 @@ github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
|
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
|
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
|
||||||
|
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
|
||||||
|
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
|
|
|
@ -123,14 +123,9 @@ type StandardizedProperties struct {
|
||||||
Fee string `json:"fee" bson:"fee"`
|
Fee string `json:"fee" bson:"fee"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ParsedPayload struct {
|
|
||||||
TokenAddress string `json:"tokenAddress"`
|
|
||||||
TokenChain int `json:"tokenChain"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseVaaWithStandarizedPropertiesdResponse represent a parse vaa response.
|
// ParseVaaWithStandarizedPropertiesdResponse represent a parse vaa response.
|
||||||
type ParseVaaWithStandarizedPropertiesdResponse struct {
|
type ParseVaaWithStandarizedPropertiesdResponse struct {
|
||||||
ParsedPayload *ParsedPayload `json:"parsedPayload"`
|
ParsedPayload any `json:"parsedPayload"`
|
||||||
StandardizedProperties StandardizedProperties `json:"standardizedProperties"`
|
StandardizedProperties StandardizedProperties `json:"standardizedProperties"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue