github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/warp/payload/addressed_call.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package payload 5 6 import "fmt" 7 8 var _ Payload = (*AddressedCall)(nil) 9 10 // AddressedCall defines the format for delivering a call across VMs including a 11 // source address and a payload. 12 // 13 // Note: If a destination address is expected, it should be encoded in the 14 // payload. 15 type AddressedCall struct { 16 SourceAddress []byte `serialize:"true"` 17 Payload []byte `serialize:"true"` 18 19 bytes []byte 20 } 21 22 // NewAddressedCall creates a new *AddressedCall and initializes it. 23 func NewAddressedCall(sourceAddress []byte, payload []byte) (*AddressedCall, error) { 24 ap := &AddressedCall{ 25 SourceAddress: sourceAddress, 26 Payload: payload, 27 } 28 return ap, initialize(ap) 29 } 30 31 // ParseAddressedCall converts a slice of bytes into an initialized 32 // AddressedCall. 33 func ParseAddressedCall(b []byte) (*AddressedCall, error) { 34 payloadIntf, err := Parse(b) 35 if err != nil { 36 return nil, err 37 } 38 payload, ok := payloadIntf.(*AddressedCall) 39 if !ok { 40 return nil, fmt.Errorf("%w: %T", errWrongType, payloadIntf) 41 } 42 return payload, nil 43 } 44 45 // Bytes returns the binary representation of this payload. It assumes that the 46 // payload is initialized from either NewAddressedCall or Parse. 47 func (a *AddressedCall) Bytes() []byte { 48 return a.bytes 49 } 50 51 func (a *AddressedCall) initialize(bytes []byte) { 52 a.bytes = bytes 53 }