scval

package
v0.0.0-...-a4ee913 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package scval provides shared helper functions for converting between Go types and Stellar Soroban xdr.ScVal values. These helpers are used by all generated contract bindings and hand-written extras.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressBytes32SliceToScVal

func AddressBytes32SliceToScVal(items [][32]byte) xdr.ScVal

func AddressFromScVal

func AddressFromScVal(val xdr.ScVal) (string, error)

AddressFromScVal extracts a strkey address from an xdr.ScVal.

func AddressSliceToScVal

func AddressSliceToScVal(items []string) xdr.ScVal

AddressSliceToScVal converts a slice of address strings to an xdr.ScVal vector.

func AddressToScVal

func AddressToScVal(addr string) xdr.ScVal

AddressToScVal converts a Stellar address string (G... or C...) to an xdr.ScVal.

func AddressVecFromScVal

func AddressVecFromScVal(val xdr.ScVal) ([][]byte, error)

AddressVecFromScVal extracts raw 32-byte addresses from a Vec<Address> ScVal.

func BoolToScVal

func BoolToScVal(v bool) xdr.ScVal

BoolToScVal converts a bool to an xdr.ScVal.

func BuildContractScAddress

func BuildContractScAddress(contractIDBytes []byte) *xdr.ScAddress

BuildContractScAddress creates an ScAddress for a contract from raw bytes.

func BuildStructScVal

func BuildStructScVal(fields map[string]xdr.ScVal) (xdr.ScVal, error)

BuildStructScVal builds a struct xdr.ScVal from a map of field names to values. Soroban requires ScMap keys to be sorted lexicographically.

func Bytes4FromScVal

func Bytes4FromScVal(val xdr.ScVal) ([4]byte, error)

Bytes4FromScVal extracts a [4]byte from an xdr.ScVal containing BytesN<4>.

func Bytes4SliceToScVal

func Bytes4SliceToScVal(items [][4]byte) xdr.ScVal

Bytes4SliceToScVal converts a slice of [4]byte to an xdr.ScVal vector (for Vec<BytesN<4>>).

func Bytes4ToScVal

func Bytes4ToScVal(b [4]byte) xdr.ScVal

Bytes4ToScVal converts a [4]byte to an xdr.ScVal (for BytesN<4>).

func Bytes16FromScVal

func Bytes16FromScVal(val xdr.ScVal) ([16]byte, error)

Bytes16FromScVal extracts a [16]byte from an xdr.ScVal containing BytesN<16>.

func Bytes16SliceToScVal

func Bytes16SliceToScVal(items [][16]byte) xdr.ScVal

Bytes16SliceToScVal converts a slice of [16]byte to an xdr.ScVal vector (for Vec<BytesN<16>>).

func Bytes16ToScVal

func Bytes16ToScVal(b [16]byte) xdr.ScVal

Bytes16ToScVal converts a [16]byte to an xdr.ScVal.

func Bytes32FromScVal

func Bytes32FromScVal(val xdr.ScVal) ([32]byte, error)

Bytes32FromScVal extracts a [32]byte from an xdr.ScVal containing BytesN<32>.

func Bytes32SliceToScVal

func Bytes32SliceToScVal(items [][32]byte) xdr.ScVal

Bytes32SliceToScVal converts a slice of [32]byte to an xdr.ScVal vector (for Vec<BytesN<32>>).

func Bytes32ToScVal

func Bytes32ToScVal(b [32]byte) xdr.ScVal

Bytes32ToScVal converts a [32]byte to an xdr.ScVal.

func BytesFromScVal

func BytesFromScVal(val xdr.ScVal) ([]byte, error)

BytesFromScVal extracts a byte slice from an xdr.ScVal containing Bytes.

func BytesSliceToScVal

func BytesSliceToScVal(items [][]byte) xdr.ScVal

StringSliceToScVal converts a slice of strings to an xdr.ScVal vector.

func BytesToScVal

func BytesToScVal(b []byte) xdr.ScVal

BytesToScVal converts a byte slice to an xdr.ScVal.

func BytesVecFromScVal

func BytesVecFromScVal(val xdr.ScVal) ([][]byte, error)

BytesVecFromScVal decodes a Vec<Bytes> from an xdr.ScVal vector.

func HexToContractStrkey

func HexToContractStrkey(hexAddr string) (string, error)

HexToContractStrkey converts a 0x-prefixed hex string (32-byte contract ID) to a Stellar contract strkey (C...).

func I128FromScVal

func I128FromScVal(val xdr.ScVal) (int64, error)

I128FromScVal extracts an int64 from an xdr.ScVal containing i128. Note: This truncates to int64 for simplicity.

func I128ToScVal

func I128ToScVal(v int64) xdr.ScVal

I128ToScVal converts an int64 to an xdr.ScVal representing i128.

func MustToScVal

func MustToScVal(val xdr.ScVal, err error) xdr.ScVal

MustToScVal panics if ToScVal returns an error.

func OptionalAddressFromScVal

func OptionalAddressFromScVal(val xdr.ScVal) (*string, error)

OptionalAddressFromScVal extracts a *string from an ScVal. ScvVoid returns nil (Option::None), ScvAddress returns a pointer to the address string (Option::Some).

func OptionalAddressToScVal

func OptionalAddressToScVal(addr *string) xdr.ScVal

OptionalAddressToScVal converts a *string to an ScVal. nil maps to ScvVoid (Soroban Option::None), non-nil maps to ScvAddress (Option::Some).

func ParseAddress

func ParseAddress(addr string) *xdr.ScAddress

ParseAddress parses a Stellar address string (G... or C...) into an xdr.ScAddress.

func RawBytesFromAddressScVal

func RawBytesFromAddressScVal(val xdr.ScVal) ([]byte, error)

RawBytesFromAddressScVal extracts the raw 32-byte key (contract ID or ed25519 pubkey) from an xdr.ScVal address.

func StringFromScVal

func StringFromScVal(val xdr.ScVal) (string, error)

StringFromScVal extracts a Go string from an xdr.ScVal containing Soroban String.

func StringToScVal

func StringToScVal(s string) xdr.ScVal

StringToScVal converts a Go string to an xdr.ScVal representing Soroban String.

func StructSliceToScVal

func StructSliceToScVal[T interface{ ToScVal() (xdr.ScVal, error) }](items []T) xdr.ScVal

StructSliceToScVal converts a slice of structs with ToScVal to an xdr.ScVal vector.

func SymbolFromScVal

func SymbolFromScVal(val xdr.ScVal) (string, error)

SymbolFromScVal extracts a string from an xdr.ScVal containing a symbol.

func SymbolToScVal

func SymbolToScVal(sym string) xdr.ScVal

SymbolToScVal converts a string to an xdr.ScVal symbol.

func SymbolToScValPtr

func SymbolToScValPtr(sym string) *xdr.ScVal

SymbolToScValPtr returns a pointer to a symbol ScVal.

func U128ToScVal

func U128ToScVal(parts xdr.UInt128Parts) xdr.ScVal

U128ToScVal converts xdr.UInt128Parts to an xdr.ScVal representing u128.

func Uint32FromScVal

func Uint32FromScVal(val xdr.ScVal) (uint32, error)

Uint32FromScVal extracts a uint32 from an xdr.ScVal.

func Uint32SliceToScVal

func Uint32SliceToScVal(items []uint32) xdr.ScVal

func Uint32ToScVal

func Uint32ToScVal(v uint32) xdr.ScVal

Uint32ToScVal converts a uint32 to an xdr.ScVal.

func Uint64FromScVal

func Uint64FromScVal(val xdr.ScVal) (uint64, error)

Uint64FromScVal extracts a uint64 from an xdr.ScVal.

func Uint64SliceToScVal

func Uint64SliceToScVal(items []uint64) xdr.ScVal

func Uint64ToScVal

func Uint64ToScVal(v uint64) xdr.ScVal

Uint64ToScVal converts a uint64 to an xdr.ScVal.

func VecToScVal

func VecToScVal(items []xdr.ScVal) xdr.ScVal

VecToScVal converts a slice of xdr.ScVal into a vector xdr.ScVal.

func VoidScVal

func VoidScVal() xdr.ScVal

VoidScVal returns an ScVal representing Soroban's void/None value.

Types

type U128

type U128 xdr.UInt128Parts

U128 represents a Soroban u128 value. It wraps xdr.UInt128Parts and implements ToScVal for use in generated struct serialization.

func U128FromScVal

func U128FromScVal(val xdr.ScVal) (U128, error)

U128FromScVal extracts U128 from an xdr.ScVal containing u128.

func (U128) ToScVal

func (u U128) ToScVal() (xdr.ScVal, error)

ToScVal converts U128 to an xdr.ScVal for contract calls.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL