wire

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package wire enables communication between go-perun and the Stellar blockchain. It defines the encoding of types required by go-perun and ensures the compatibility to the types used in Soroban smart contracts.

Index

Constants

View Source
const (
	SymbolBalancesBalA  xdr.ScSymbol = "bal_a"
	SymbolBalancesBalB  xdr.ScSymbol = "bal_b"
	SymbolBalancesToken xdr.ScSymbol = "token"
)
View Source
const (
	SymbolChannelParams  = "params"
	SymbolChannelState   = "state"
	SymbolChannelControl = "control"
)
View Source
const (
	SymbolControlFundedA    = "funded_a"
	SymbolControlFundedB    = "funded_b"
	SymbolControlClosed     = "closed"
	SymbolControlWithdrawnA = "withdrawn_a"
	SymbolControlWithdrawnB = "withdrawn_b"
	SymbolControlDisputed   = "disputed"
	SymbolControlTimestamp  = "timestamp"
)
View Source
const (
	SymbolParamsA                 = "a"
	SymbolParamsB                 = "b"
	SymbolParamsNonce             = "nonce"
	SymbolParamsChallengeDuration = "challenge_duration"
)
View Source
const (
	PubKeyLength                         = 32
	SymbolParticipantAddr   xdr.ScSymbol = "addr"
	SymbolParticipantPubKey xdr.ScSymbol = "pubkey"
)
View Source
const (
	SymbolStateChannelID xdr.ScSymbol = "channel_id"
	SymbolStateBalances  xdr.ScSymbol = "balances"
	SymbolStateVersion   xdr.ScSymbol = "version"
	SymbolStateFinalized xdr.ScSymbol = "finalized"
)
View Source
const ChannelIDLength = 32
View Source
const NonceLength = 32

Variables

View Source
var MaxBalance = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 127), big.NewInt(1))

Functions

func GetMapValue

func GetMapValue(key xdr.ScVal, m xdr.ScMap) (xdr.ScVal, error)

func GetScMapEntry

func GetScMapEntry(key xdr.ScVal, m xdr.ScMap) (xdr.ScMapEntry, error)

func GetScMapValueFromSymbol

func GetScMapValueFromSymbol(key xdr.ScSymbol, m xdr.ScMap) (xdr.ScVal, error)

func MakeInt128Parts

func MakeInt128Parts(i *big.Int) (xdr.Int128Parts, error)

MakeInt128Parts converts a big.Int to xdr.Int128Parts. It returns an error if the big.Int is negative or too large.

func MakeNonce

func MakeNonce(nonce channel.Nonce) xdr.ScBytes

func MakeSymbolScMap

func MakeSymbolScMap(keys []xdr.ScSymbol, values []xdr.ScVal) (xdr.ScMap, error)

MakeSymbolScMap creates a xdr.ScMap from a slice of symbols and a slice of values. The entries are sorted lexicographically by symbol. We expect that keys does not contain duplicates.

func ToAllocation

func ToAllocation(b Balances) (*channel.Allocation, error)

func ToBigInt

func ToBigInt(i xdr.Int128Parts) (*big.Int, error)

func ToNonce

func ToNonce(bytes xdr.ScBytes) channel.Nonce

func ToParams

func ToParams(params Params) (channel.Params, error)

func ToParticipant

func ToParticipant(participant Participant) (types.Participant, error)

func ToState

func ToState(stellarState State) (channel.State, error)

Types

type Balances

type Balances struct {
	BalA  xdr.Int128Parts
	BalB  xdr.Int128Parts
	Token xdr.ScAddress
}

func BalancesFromScVal

func BalancesFromScVal(v xdr.ScVal) (Balances, error)

func MakeBalances

func MakeBalances(alloc channel.Allocation) (Balances, error)

func (*Balances) DecodeFrom

func (b *Balances) DecodeFrom(d *xdr3.Decoder) (int, error)

func (Balances) EncodeTo

func (b Balances) EncodeTo(e *xdr3.Encoder) error

func (*Balances) FromScVal

func (b *Balances) FromScVal(v xdr.ScVal) error

func (Balances) MarshalBinary

func (b Balances) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (Balances) ToScVal

func (b Balances) ToScVal() (xdr.ScVal, error)

func (*Balances) UnmarshalBinary

func (b *Balances) UnmarshalBinary(data []byte) error

type Channel

type Channel struct {
	Params  Params
	State   State
	Control Control
}

func ChannelFromScVal

func ChannelFromScVal(v xdr.ScVal) (Channel, error)

func MakeChannel

func MakeChannel(p Params, s State, c Control) Channel

func (*Channel) DecodeFrom

func (c *Channel) DecodeFrom(d *xdr3.Decoder) (int, error)

func (Channel) EncodeTo

func (c Channel) EncodeTo(e *xdr3.Encoder) error

func (*Channel) FromScVal

func (c *Channel) FromScVal(v xdr.ScVal) error

func (Channel) MarshalBinary

func (c Channel) MarshalBinary() ([]byte, error)

func (Channel) ToScVal

func (c Channel) ToScVal() (xdr.ScVal, error)

func (*Channel) UnmarshalBinary

func (c *Channel) UnmarshalBinary(data []byte) error

type Control

type Control struct {
	FundedA    bool
	FundedB    bool
	Closed     bool
	WithdrawnA bool
	WithdrawnB bool
	Disputed   bool
	Timestamp  xdr.Uint64
}

func ControlFromScVal

func ControlFromScVal(v xdr.ScVal) (Control, error)

func (*Control) DecodeFrom

func (c *Control) DecodeFrom(d *xdr3.Decoder) (int, error)

func (Control) EncodeTo

func (c Control) EncodeTo(e *xdr3.Encoder) error

func (*Control) FromScVal

func (c *Control) FromScVal(v xdr.ScVal) error

func (Control) MarshalBinary

func (c Control) MarshalBinary() ([]byte, error)

func (Control) ToScVal

func (c Control) ToScVal() (xdr.ScVal, error)

func (*Control) UnmarshalBinary

func (c *Control) UnmarshalBinary(data []byte) error

type Params

type Params struct {
	A                 Participant
	B                 Participant
	Nonce             xdr.ScBytes
	ChallengeDuration xdr.Uint64
}

func MakeParams

func MakeParams(params channel.Params) (Params, error)

func MustMakeParams

func MustMakeParams(params channel.Params) Params

func ParamsFromScVal

func ParamsFromScVal(v xdr.ScVal) (Params, error)

func (*Params) DecodeFrom

func (p *Params) DecodeFrom(d *xdr3.Decoder) (int, error)

func (Params) EncodeTo

func (p Params) EncodeTo(e *xdr3.Encoder) error

func (*Params) FromScVal

func (p *Params) FromScVal(v xdr.ScVal) error

func (Params) MarshalBinary

func (p Params) MarshalBinary() ([]byte, error)

func (Params) ToScVal

func (p Params) ToScVal() (xdr.ScVal, error)

func (*Params) UnmarshalBinary

func (p *Params) UnmarshalBinary(data []byte) error

type Participant

type Participant struct {
	Addr   xdr.ScAddress
	PubKey xdr.ScBytes
}

func MakeParticipant

func MakeParticipant(participant types.Participant) (Participant, error)

func ParticipantFromScVal

func ParticipantFromScVal(v xdr.ScVal) (Participant, error)

func (*Participant) DecodeFrom

func (p *Participant) DecodeFrom(d *xdr3.Decoder) (int, error)

func (Participant) EncodeTo

func (p Participant) EncodeTo(e *xdr3.Encoder) error

func (*Participant) FromScVal

func (p *Participant) FromScVal(v xdr.ScVal) error

func (Participant) MarshalBinary

func (p Participant) MarshalBinary() ([]byte, error)

func (Participant) ToScVal

func (p Participant) ToScVal() (xdr.ScVal, error)

func (*Participant) UnmarshalBinary

func (p *Participant) UnmarshalBinary(data []byte) error

type State

type State struct {
	ChannelID xdr.ScBytes
	Balances  Balances
	Version   xdr.Uint64
	Finalized bool
}

func MakeState

func MakeState(state channel.State) (State, error)

func StateFromScVal

func StateFromScVal(v xdr.ScVal) (State, error)

func (*State) DecodeFrom

func (s *State) DecodeFrom(d *xdr3.Decoder) (int, error)

func (State) EncodeTo

func (s State) EncodeTo(e *xdr3.Encoder) error

func (*State) FromScVal

func (s *State) FromScVal(v xdr.ScVal) error

func (State) MarshalBinary

func (s State) MarshalBinary() ([]byte, error)

func (State) ToScVal

func (s State) ToScVal() (xdr.ScVal, error)

func (*State) UnmarshalBinary

func (s *State) UnmarshalBinary(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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