rippleTransaction

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACCOUNT_ZERO = "rrrrrrrrrrrrrrrrrrrrrhoLvTp"
	ACCOUNT_ONE  = "rrrrrrrrrrrrrrrrrrrrBZbvji"
	NaN          = "rrrrrrrrrrrrrrrrrrrn5RM1rHd"
	ROOT         = "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"
)
View Source
const (
	PATH_BOUNDARY pathEntry = 0xFF
	PATH_END      pathEntry = 0x00

	PATH_ACCOUNT  pathEntry = 0x01
	PATH_REDEEM   pathEntry = 0x02
	PATH_CURRENCY pathEntry = 0x10
	PATH_ISSUER   pathEntry = 0x20
)
View Source
const (
	AddressPrefix        byte   = 0x00
	PAYMENT              uint16 = 0x00
	HP_TRANSACTION_SIGN  uint32 = 0x53545800
	TxCanonicalSignature uint32 = 0x80000000
	// Payment flags
	TxNoDirectRipple uint32 = 0x00010000
	TxPartialPayment uint32 = 0x00020000
	TxLimitQuality   uint32 = 0x00040000
	TxCircle         uint32 = 0x00080000 // Not implemented
)
View Source
const (
	ST_UINT16  uint8 = 1
	ST_UINT32  uint8 = 2
	ST_AMOUNT  uint8 = 6
	ST_VL      uint8 = 7
	ST_ACCOUNT uint8 = 8
	ST_OBJECT  uint8 = 14
	ST_ARRAY   uint8 = 15
	ST_PATHSET uint8 = 18
)

Variables

View Source
var (
	CurveOrder     = []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x41}
	HalfCurveOrder = []byte{0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x5D, 0x57, 0x6E, 0x73, 0x57, 0xA4, 0x50, 0x1D, 0xDF, 0xE9, 0x2F, 0x46, 0x68, 0x1B, 0x20, 0xA0}
)
View Source
var (
	ErrorInvalidBase58String = errors.New("invalid base58 string")
)

Errors

View Source
var (
	RippleAlphabet = NewAlphabet("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz")
)

Alphabet: copy from https://en.wikipedia.org/wiki/Base58

Functions

func Base58Decode added in v1.0.11

func Base58Decode(b, alphabet string) ([]byte, error)

Base58Decode decodes a modified base58 string to a byte slice and checks checksum.

func Base58Encode added in v1.0.11

func Base58Encode(b []byte, alphabet string) string

Base58Encode encodes a byte slice to a modified base58 string.

func CreateEmptyRawTransactionAndHash

func CreateEmptyRawTransactionAndHash(from, pubkey string, destinationTag int64, sequence uint32, to string, amount, fee uint64, lastLedgerSequence uint32, memoType, memoData, memoFormat string) (string, string, error)

func CreateTokenEmptyRawTransactionAndHash added in v1.0.11

func CreateTokenEmptyRawTransactionAndHash(from, pubkey string, destinationTag int64, sequence uint32, to string, amount *Amount, fee uint64, lastLedgerSequence uint32, memoType, memoData, memoFormat string) (string, string, error)

func Decode

func Decode(input string, alphabet *Alphabet) ([]byte, error)

Decode docode with custom alphabet

func Encode

func Encode(input []byte, alphabet *Alphabet) string

Encode encode with custom alphabet

func GetProgramHashFromAddress

func GetProgramHashFromAddress(address string) ([]byte, error)

func SignRawTransaction

func SignRawTransaction(hash string, prikey []byte) (string, error)

func VerifyAndCombinRawTransaction

func VerifyAndCombinRawTransaction(emptyTrans string, signature, publicKey string) (bool, string)

Types

type Account added in v1.0.11

type Account [20]byte

func NewAccountFromAddress added in v1.0.11

func NewAccountFromAddress(s string) (*Account, error)

Expects address in base58 form

func (*Account) Bytes added in v1.0.11

func (a *Account) Bytes() []byte

func (Account) Hash added in v1.0.11

func (a Account) Hash() (Hash, error)

func (Account) IsZero added in v1.0.11

func (a Account) IsZero() bool

func (Account) String added in v1.0.11

func (a Account) String() string

type Alphabet

type Alphabet struct {
	// contains filtered or unexported fields
}

Alphabet The base58 alphabet object.

func NewAlphabet

func NewAlphabet(alphabet string) *Alphabet

NewAlphabet create a custom alphabet from 58-length string. Note: len(rune(alphabet)) must be 58.

func (Alphabet) String

func (alphabet Alphabet) String() string

Alphabet's string representation

type Amount added in v1.0.11

type Amount struct {
	*Value
	Currency Currency
	Issuer   Account
}

func NewAmount added in v1.0.11

func NewAmount(v interface{}) (*Amount, error)

Requires v to be in computer parsable form

func (Amount) Abs added in v1.0.11

func (a Amount) Abs() *Amount

func (Amount) Add added in v1.0.11

func (a Amount) Add(b *Amount) (*Amount, error)

func (Amount) ApplyInterest added in v1.0.11

func (a Amount) ApplyInterest() (*Amount, error)

func (Amount) Asset added in v1.0.11

func (a Amount) Asset() *Asset

func (Amount) Bytes added in v1.0.11

func (a Amount) Bytes() []byte

func (Amount) Clone added in v1.0.11

func (a Amount) Clone() *Amount

func (Amount) Divide added in v1.0.11

func (a Amount) Divide(b *Amount) (*Amount, error)

func (Amount) Equals added in v1.0.11

func (a Amount) Equals(b Amount) bool

func (Amount) IsPositive added in v1.0.11

func (a Amount) IsPositive() bool

func (Amount) Machine added in v1.0.11

func (a Amount) Machine() string

Amount in computer parsable form

func (*Amount) Marshal added in v1.0.11

func (a *Amount) Marshal(w io.Writer) error

func (Amount) MarshalBinary added in v1.0.11

func (a Amount) MarshalBinary() ([]byte, error)

func (Amount) Multiply added in v1.0.11

func (a Amount) Multiply(b *Amount) (*Amount, error)

func (Amount) Negate added in v1.0.11

func (a Amount) Negate() *Amount

func (Amount) Ratio added in v1.0.11

func (a Amount) Ratio(b Amount) *Value

Ratio returns the ratio between a and b. Returns a zero value when division is impossible

func (Amount) SameValue added in v1.0.11

func (a Amount) SameValue(b *Amount) bool

Returns true if the values are equal, but ignores the currency and issuer

func (Amount) String added in v1.0.11

func (a Amount) String() string

Amount in human parsable form with demurrage applied

func (Amount) Subtract added in v1.0.11

func (a Amount) Subtract(b *Amount) (*Amount, error)

func (*Amount) Unmarshal added in v1.0.11

func (a *Amount) Unmarshal(r Reader) error

func (*Amount) UnmarshalBinary added in v1.0.11

func (a *Amount) UnmarshalBinary(b []byte) error

func (Amount) ZeroClone added in v1.0.11

func (a Amount) ZeroClone() *Amount

Returns a new Amount with the same currency and issuer, but a zero value

type Asset added in v1.0.11

type Asset struct {
	Currency string `json:"currency"`
	Issuer   string `json:"issuer,omitempty"`
}

func NewAsset added in v1.0.11

func NewAsset(s string) (*Asset, error)

func (*Asset) IsNative added in v1.0.11

func (a *Asset) IsNative() bool

func (*Asset) Matches added in v1.0.11

func (a *Asset) Matches(amount *Amount) bool

func (Asset) String added in v1.0.11

func (a Asset) String() string

type Currency added in v1.0.11

type Currency [20]byte

func NewCurrency added in v1.0.11

func NewCurrency(s string) (Currency, error)

Accepts currency as either a 3 character code or a 40 character hex string

func (*Currency) Bytes added in v1.0.11

func (c *Currency) Bytes() []byte

func (Currency) Clone added in v1.0.11

func (c Currency) Clone() Currency

func (Currency) Compare added in v1.0.11

func (a Currency) Compare(b Currency) int

func (Currency) Equals added in v1.0.11

func (c Currency) Equals(other Currency) bool

func (Currency) IsNative added in v1.0.11

func (c Currency) IsNative() bool

func (Currency) Less added in v1.0.11

func (a Currency) Less(b Currency) bool

func (Currency) Machine added in v1.0.11

func (c Currency) Machine() string

Currency in computer parsable form

func (*Currency) Marshal added in v1.0.11

func (c *Currency) Marshal(w io.Writer) error

func (Currency) Rate added in v1.0.11

func (c Currency) Rate(seconds uint32) float64

func (Currency) String added in v1.0.11

func (c Currency) String() string

Currency in human parsable form Demurrage is formatted, for example, as XAU (0.50%pa)

func (Currency) Type added in v1.0.11

func (c Currency) Type() CurrencyType

func (*Currency) Unmarshal added in v1.0.11

func (c *Currency) Unmarshal(r Reader) error

type CurrencyAmount added in v1.0.11

type CurrencyAmount struct {
	Currency string
	Value    string
	Issuer   string
}

type CurrencyType added in v1.0.11

type CurrencyType uint8
const (
	CT_XRP       CurrencyType = 0
	CT_STANDARD  CurrencyType = 1
	CT_DEMURRAGE CurrencyType = 2
	CT_HEX       CurrencyType = 3
	CT_UNKNOWN   CurrencyType = 4
)

type ExchangeRate added in v1.0.11

type ExchangeRate uint64

func NewExchangeRate added in v1.0.11

func NewExchangeRate(a, b *Amount) (ExchangeRate, error)

func (*ExchangeRate) Bytes added in v1.0.11

func (e *ExchangeRate) Bytes() []byte

type Hash added in v1.0.11

type Hash interface {
	Version() HashVersion
	Payload() []byte
	PayloadTrimmed() []byte
	Value() *big.Int
	String() string
	Clone() Hash
	MarshalText() ([]byte, error)
}

func AccountId added in v1.0.11

func AccountId(key Key, sequence *uint32) (Hash, error)

func AccountPrivateKey added in v1.0.11

func AccountPrivateKey(key Key, sequence *uint32) (Hash, error)

func AccountPublicKey added in v1.0.11

func AccountPublicKey(key Key, sequence *uint32) (Hash, error)

func NewAccountId added in v1.0.11

func NewAccountId(b []byte) (Hash, error)

func NewAccountPrivateKey added in v1.0.11

func NewAccountPrivateKey(b []byte) (Hash, error)

func NewAccountPublicKey added in v1.0.11

func NewAccountPublicKey(b []byte) (Hash, error)

func NewFamilySeed added in v1.0.11

func NewFamilySeed(b []byte) (Hash, error)

func NewNodePrivateKey added in v1.0.11

func NewNodePrivateKey(b []byte) (Hash, error)

func NewNodePublicKey added in v1.0.11

func NewNodePublicKey(b []byte) (Hash, error)

func NewRippleHash added in v1.0.11

func NewRippleHash(s string) (Hash, error)

func NewRippleHashCheck added in v1.0.11

func NewRippleHashCheck(s string, version HashVersion) (Hash, error)

Checks hash matches expected version

func NodePrivateKey added in v1.0.11

func NodePrivateKey(key Key) (Hash, error)

func NodePublicKey added in v1.0.11

func NodePublicKey(key Key) (Hash, error)

type HashVersion added in v1.0.11

type HashVersion byte
const (
	ALPHABET = "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"

	RIPPLE_ACCOUNT_ID      HashVersion = 0
	RIPPLE_NODE_PUBLIC     HashVersion = 28
	RIPPLE_NODE_PRIVATE    HashVersion = 32
	RIPPLE_FAMILY_SEED     HashVersion = 33
	RIPPLE_ACCOUNT_PRIVATE HashVersion = 34
	RIPPLE_ACCOUNT_PUBLIC  HashVersion = 35
)

type Key added in v1.0.11

type Key interface {
	Private(*uint32) []byte
	Id(*uint32) []byte
	Public(*uint32) []byte
}

type LimitByteReader added in v1.0.11

type LimitByteReader struct {
	R Reader // underlying reader
	N int64  // max bytes remaining
}

func LimitedByteReader added in v1.0.11

func LimitedByteReader(r Reader, n int64) *LimitByteReader

func (*LimitByteReader) Len added in v1.0.11

func (l *LimitByteReader) Len() int

func (*LimitByteReader) Read added in v1.0.11

func (l *LimitByteReader) Read(p []byte) (n int, err error)

func (*LimitByteReader) ReadByte added in v1.0.11

func (l *LimitByteReader) ReadByte() (c byte, err error)

func (*LimitByteReader) UnreadByte added in v1.0.11

func (l *LimitByteReader) UnreadByte() error

type Path added in v1.0.11

type Path []PathElem

Path represents a single path of liquidity that a transaction may use.

func NewPath added in v1.0.11

func NewPath(s string) (Path, error)

NewPath accepts a path consisting of hops delimited by "=>" where each hop is either "<currency>/<issuer>" or "<account>". Whitespace around the delimiter is acceptable and is ignored.

func (Path) Signature added in v1.0.11

func (p Path) Signature() (uint32, error)

func (Path) String added in v1.0.11

func (p Path) String() string

type PathElem added in v1.0.11

type PathElem struct {
	Account  *Account
	Currency *Currency
	Issuer   *Account
}

PathElem represents one link in a path.

func (PathElem) MarshalJSON added in v1.0.11

func (p PathElem) MarshalJSON() ([]byte, error)

func (PathElem) String added in v1.0.11

func (p PathElem) String() string

type PathSet added in v1.0.11

type PathSet []Path

PathSet represents a collection of possible paths that a transaction may use.

func (*PathSet) Marshal added in v1.0.11

func (p *PathSet) Marshal() ([]byte, error)

func (*PathSet) Unmarshal added in v1.0.11

func (p *PathSet) Unmarshal(r Reader) error

type Reader added in v1.0.11

type Reader interface {
	io.ByteScanner
	io.Reader
	Len() int
}

func NewVariableByteReader added in v1.0.11

func NewVariableByteReader(r Reader) (Reader, error)

type RippleTime added in v1.0.11

type RippleTime struct {
	T uint32
}

Represents a time as the number of seconds since the Ripple epoch: January 1st, 2000 (00:00 UTC)

func NewRippleTime added in v1.0.11

func NewRippleTime(t uint32) *RippleTime

func Now added in v1.0.11

func Now() *RippleTime

func (*RippleTime) SetString added in v1.0.11

func (t *RippleTime) SetString(s string) error

Accepts time formatted as 2006-Jan-02 15:04:05

func (*RippleTime) SetUint32 added in v1.0.11

func (t *RippleTime) SetUint32(n uint32)

func (RippleTime) Short added in v1.0.11

func (t RippleTime) Short() string

Returns time formatted as 15:04:05

func (RippleTime) String added in v1.0.11

func (t RippleTime) String() string

Returns time formatted as 2006-Jan-02 15:04:05

func (RippleTime) Time added in v1.0.11

func (t RippleTime) Time() time.Time

func (RippleTime) Uint32 added in v1.0.11

func (t RippleTime) Uint32() uint32

type TxStruct

type TxStruct struct {
	TransactionType    []byte
	Flags              []byte
	Sequence           []byte
	LastLedgerSequence []byte
	Amount             []byte
	Fee                []byte
	SigningPubKey      []byte
	TxnSignature       []byte
	Account            []byte
	Destination        []byte
	DestinationTag     []byte
	Memos              []byte
	Paths              []byte
	SendMax            []byte //如果SendMax交易指令中省略了该字段,则认为它等于Amount

}

func NewTxStruct

func NewTxStruct(from, pubkey string, sequence uint32, to string, amount []byte, fee uint64, signature string, destinationTag int64, lastLedgerSequence uint32, memoType, memoData, memoFormat string, flags uint32) (*TxStruct, error)

func (TxStruct) GetHash

func (tx TxStruct) GetHash() []byte

func (TxStruct) ToBytes

func (tx TxStruct) ToBytes() []byte

func (TxStruct) ToEmptyRawWiths

func (tx TxStruct) ToEmptyRawWiths() string

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value is the numeric type in Ripple. It can store numbers in two different representations: native and non-native. Non-native numbers are stored as a mantissa (Num) in the range [1e15,1e16) plus an exponent (Offset) in the range [-96,80]. Native values are stored as an integer number of "drips" each representing 1/1000000. Throughout the library, native values are interpreted as drips unless otherwise specified.

func NewNativeValue added in v1.0.11

func NewNativeValue(n int64) (*Value, error)

NewNativeValue returns a Value with n drops. If the value is impossible an error is returned.

func NewNonNativeValue added in v1.0.11

func NewNonNativeValue(n int64, offset int64) (*Value, error)

NewNonNativeValue returns a Value of n*10^offset.

func NewValue added in v1.0.11

func NewValue(s string, native bool) (*Value, error)

NewValue accepts a string representation of a value and a flag to indicate if it should be stored as native. If the native flag is set AND a decimal is used, the number is interpreted as XRP. If no decimal is used, it is interpreted as drips.

func (Value) Abs added in v1.0.11

func (v Value) Abs() *Value

Abs returns a copy of v with a positive sign.

func (Value) Add added in v1.0.11

func (a Value) Add(b Value) (*Value, error)

Add adds a to b and returns the sum as a new Value.

func (*Value) Bytes

func (v *Value) Bytes() []byte

func (Value) Clone added in v1.0.11

func (v Value) Clone() *Value

Clone returns a Value which is a copy of v.

func (Value) Compare added in v1.0.11

func (a Value) Compare(b Value) int

Compare returns an integer comparing two Values. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.

func (Value) Divide added in v1.0.11

func (num Value) Divide(den Value) (*Value, error)

func (Value) Equals added in v1.0.11

func (a Value) Equals(b Value) bool

func (Value) Float added in v1.0.11

func (v Value) Float() float64

func (Value) IsNative

func (v Value) IsNative() bool

func (Value) IsNegative added in v1.0.11

func (v Value) IsNegative() bool

func (Value) IsZero added in v1.0.11

func (v Value) IsZero() bool

func (Value) Less added in v1.0.11

func (a Value) Less(b Value) bool

Less compares values and returns true if a is less than b.

func (*Value) Marshal added in v1.0.11

func (v *Value) Marshal(w io.Writer) error

func (Value) MarshalBinary added in v1.0.11

func (v Value) MarshalBinary() ([]byte, error)

func (Value) Multiply added in v1.0.11

func (a Value) Multiply(b Value) (*Value, error)

func (Value) Native added in v1.0.11

func (v Value) Native() (*Value, error)

Native returns a clone of the value in native format.

func (Value) Negate added in v1.0.11

func (v Value) Negate() *Value

Negate returns a new Value with the opposite sign of v.

func (Value) NonNative added in v1.0.11

func (v Value) NonNative() (*Value, error)

NonNative returns a clone of the value in non-native format.

func (Value) Rat added in v1.0.11

func (v Value) Rat() *big.Rat

Rat returns the value as a big.Rat.

func (Value) Ratio added in v1.0.11

func (a Value) Ratio(b Value) (*Value, error)

Ratio returns the ratio a/b. XRP are interpreted at face value rather than drips. The result of Ratio is always a non-native Value for additional precision.

func (Value) String added in v1.0.11

func (v Value) String() string

String returns the Value as a string for human consumption. Native values are represented as decimal XRP rather than drips.

func (Value) Subtract added in v1.0.11

func (a Value) Subtract(b Value) (*Value, error)

func (*Value) Unmarshal added in v1.0.11

func (v *Value) Unmarshal(r Reader) error

func (*Value) UnmarshalBinary added in v1.0.11

func (v *Value) UnmarshalBinary(b []byte) error

func (Value) ZeroClone added in v1.0.11

func (v Value) ZeroClone() *Value

ZeroClone returns a zero Value, native or non-native depending on v's setting.

Jump to

Keyboard shortcuts

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