Documentation ¶
Index ¶
- Constants
- Variables
- func Blake2b224(raw []byte) []byte
- func Sha3AndBlake2b224(raw []byte) []byte
- func VariableNatDecode(bytes []byte) (uint64, int, bool)
- func VariableNatEncode(n uint64) []byte
- type Address
- type AddressKind
- type Asset
- type AssetName
- type BaseAddress
- type BootstrapWitness
- type EnterpriseAddress
- type Input
- type KeysWitness
- type LegacyAddress
- func (a *LegacyAddress) Bytes() []byte
- func (a *LegacyAddress) GetNetwork() Network
- func (a *LegacyAddress) Kind() AddressKind
- func (a *LegacyAddress) MarshalCBOR() ([]byte, error)
- func (a *LegacyAddress) Prefix() string
- func (a *LegacyAddress) String() string
- func (a *LegacyAddress) UnmarshalCBOR(data []byte) error
- type LegacyAddressAttribute
- type Network
- type Output
- func (o *Output) AddAmount(amount uint64) *Output
- func (o *Output) AddAsset(asset *Asset, tokenAmount uint64) *Output
- func (o *Output) AddAssetMap(raw map[[28]byte]map[AssetName]uint64)
- func (o *Output) MarshalCBOR() ([]byte, error)
- func (o *Output) MinAdaRequired() uint64
- func (o *Output) MustAddAsset(assetId string, tokenAmount uint64) *Output
- func (o *Output) SetAmount(amount uint64) *Output
- func (o *Output) SetMinAda() *Output
- func (o *Output) UnmarshalCBOR(data []byte) error
- type PointerAddress
- type Reward
- type ScriptsWitness
- type StakeCredential
- type StakeCredentialType
- type StakePoint
- type TransactionBody
- type Tx
- func (t *Tx) AddBootstrapWitness(k *BootstrapWitness) *Tx
- func (t *Tx) AddInputs(i ...*Input) *Tx
- func (t *Tx) AddKeyWitness(k *KeysWitness) *Tx
- func (t *Tx) AddOutputs(o ...*Output) *Tx
- func (t *Tx) Bytes() []byte
- func (t *Tx) Hash() []byte
- func (t *Tx) ID() string
- func (t *Tx) SetFee(fee uint64) *Tx
- func (t *Tx) SetInvalidAfter(v uint32) *Tx
- func (t *Tx) SetInvalidBefore(v uint32) *Tx
- type Witness
Examples ¶
Constants ¶
const ( B32Prefix = "addr" TestnetSuffix = "_test" StakePrefix = "stake" Hash28Size = 28 )
const ( XPubSize = 64 ByronPubKeyTag uint64 = 0 ByronTag uint64 = 24 )
Variables ¶
var ErrInvalidCredSize = errors.New("stake credential size is not 28")
Functions ¶
func Blake2b224 ¶
func Sha3AndBlake2b224 ¶
func VariableNatEncode ¶
Types ¶
type Address ¶
type Address interface { cbor.Marshaler // Raw bytes for transaction outputs Bytes() []byte // Readable and humanable string String() string // Bech32 prefix, and empty for legacy address Prefix() string // address kind Kind() AddressKind // address network GetNetwork() Network }
func DecodeAddress ¶
DecodeAddress decode humanable address it should be invalid if you get an error for an exchange, you should also check address network and address type
Example ¶
RawAddressList := []string{ "addr1v9wa6entm75duchtu50mu6u6hkagdgqzaevt0cwryaw3pnca870vt", "Ae2tdPwUPEZCdHLQP8Nke2AogJ7VgGiHbJDV3N1mWyQxy5AhwGgihL44t8w", "addr1q87ywcqelrrm9zrn4f9v5te2ss2w6f0j4ca39pwhsgxnupuec8u08zuyfu64xecytwcuc8nm6xkn0xj2sqx7m7g07fqqf96uvu", "DdzFFzCqrht7FAf8MpryP1p8sgkmFRUnDpifnnu4ZxpBjbCTSDwJVAaDsDqrC7SLYFx8fUrDcNNsD4AMiUgg2wGywTVpcfB1F3AHrGkv", } for _, address := range RawAddressList { got := MustDecodeAddress(address).String() fmt.Println(got == address) }
Output: true true true true
func DecodeRawAddress ¶
DecodeRawAddresss decodes raw address bytes it decode raw address in tx output, you may don't need it
func MustDecodeAddress ¶
type AddressKind ¶
type AddressKind byte
const ( LegacyAddressKind AddressKind = iota BaseAddressKind PointerAddressKind EnterpriseAddressKind RewardAddressKind )
func (AddressKind) String ¶
func (i AddressKind) String() string
type AssetName ¶
type AssetName struct {
// contains filtered or unexported fields
}
func NewAssetName ¶
func (AssetName) MarshalCBOR ¶
func (*AssetName) UnmarshalCBOR ¶
type BaseAddress ¶
type BaseAddress struct { Network Network Payment StakeCredential Stake StakeCredential }
func (*BaseAddress) Bytes ¶
func (b *BaseAddress) Bytes() []byte
func (*BaseAddress) GetNetwork ¶
func (b *BaseAddress) GetNetwork() Network
func (*BaseAddress) Kind ¶
func (b *BaseAddress) Kind() AddressKind
func (*BaseAddress) MarshalCBOR ¶
func (b *BaseAddress) MarshalCBOR() ([]byte, error)
func (*BaseAddress) Prefix ¶
func (b *BaseAddress) Prefix() string
func (*BaseAddress) String ¶
func (b *BaseAddress) String() string
type BootstrapWitness ¶
type BootstrapWitness struct { VKey []byte // pubkey(32 bytes) Sign []byte // ed25519 signature Chaincode []byte // chaincode Attribute []byte // byron address attributes // contains filtered or unexported fields }
BootstrapWitness the witness for Byron address
func NewBootstrapWitness ¶
func NewBootstrapWitness(addr *LegacyAddress, xpub, sig []byte) (*BootstrapWitness, error)
type EnterpriseAddress ¶
type EnterpriseAddress struct { Network Network Payment StakeCredential }
func NewEnterpriseAddress ¶
func NewEnterpriseAddress(pubkey []byte, kind StakeCredentialType, network Network) *EnterpriseAddress
NewEnterpriseAddress creates Enterprise type address with public key the pubkey param can be pubkeyHash or 32 bytes pubkey or 64 bytes xpub
func NewKeyedEnterpriseAddress ¶
func NewKeyedEnterpriseAddress(key []byte, network Network) *EnterpriseAddress
func (*EnterpriseAddress) Bytes ¶
func (e *EnterpriseAddress) Bytes() []byte
func (*EnterpriseAddress) GetNetwork ¶
func (e *EnterpriseAddress) GetNetwork() Network
func (*EnterpriseAddress) Kind ¶
func (e *EnterpriseAddress) Kind() AddressKind
func (*EnterpriseAddress) MarshalCBOR ¶
func (e *EnterpriseAddress) MarshalCBOR() ([]byte, error)
func (*EnterpriseAddress) Prefix ¶
func (e *EnterpriseAddress) Prefix() string
func (*EnterpriseAddress) String ¶
func (e *EnterpriseAddress) String() string
type Input ¶
type KeysWitness ¶
type KeysWitness struct { VKey []byte // 32bytes pubkey Sign []byte // ed25519 sign // contains filtered or unexported fields }
KeysWithness the witness for Shelly address
func NewKeysWitness ¶
func NewKeysWitness(vkey, sign []byte) *KeysWitness
type LegacyAddress ¶
type LegacyAddress struct { Hashed []byte Attrs LegacyAddressAttribute Tag uint64 // Byron only supports PubKeyTag(0) }
func NewSimpleLegacyAddress ¶
func NewSimpleLegacyAddress(xpub []byte, networks ...uint32) (*LegacyAddress, error)
func (*LegacyAddress) Bytes ¶
func (a *LegacyAddress) Bytes() []byte
func (*LegacyAddress) GetNetwork ¶
func (a *LegacyAddress) GetNetwork() Network
func (*LegacyAddress) Kind ¶
func (a *LegacyAddress) Kind() AddressKind
func (*LegacyAddress) MarshalCBOR ¶
func (a *LegacyAddress) MarshalCBOR() ([]byte, error)
func (*LegacyAddress) Prefix ¶
func (a *LegacyAddress) Prefix() string
func (*LegacyAddress) String ¶
func (a *LegacyAddress) String() string
func (*LegacyAddress) UnmarshalCBOR ¶
func (a *LegacyAddress) UnmarshalCBOR(data []byte) error
type LegacyAddressAttribute ¶
func (LegacyAddressAttribute) MarshalCBOR ¶
func (a LegacyAddressAttribute) MarshalCBOR() ([]byte, error)
func (*LegacyAddressAttribute) UnmarshalCBOR ¶
func (a *LegacyAddressAttribute) UnmarshalCBOR(data []byte) error
type Output ¶
Output transaction output
func MustOutput ¶
func MustOutputWithAssets ¶
func NewOutputWithAsset ¶
func (*Output) AddAssetMap ¶
AddAssetMap copys raw asset to outputs
func (*Output) MarshalCBOR ¶
func (*Output) MinAdaRequired ¶
MinAdaRequired computes required ada for this output learn more at https://docs.cardano.org/native-tokens/minimum-ada-value-requirement
func (*Output) MustAddAsset ¶
func (*Output) UnmarshalCBOR ¶
type PointerAddress ¶
type PointerAddress struct { Network Network Payment StakeCredential Stake StakePoint }
func (*PointerAddress) Bytes ¶
func (p *PointerAddress) Bytes() []byte
func (*PointerAddress) GetNetwork ¶
func (p *PointerAddress) GetNetwork() Network
func (*PointerAddress) Kind ¶
func (p *PointerAddress) Kind() AddressKind
func (*PointerAddress) MarshalCBOR ¶
func (p *PointerAddress) MarshalCBOR() ([]byte, error)
func (*PointerAddress) Prefix ¶
func (p *PointerAddress) Prefix() string
func (*PointerAddress) String ¶
func (p *PointerAddress) String() string
type Reward ¶
type Reward struct { Network Network Payment StakeCredential }
func (*Reward) GetNetwork ¶
func (*Reward) Kind ¶
func (r *Reward) Kind() AddressKind
func (*Reward) MarshalCBOR ¶
type ScriptsWitness ¶
type ScriptsWitness struct {
// contains filtered or unexported fields
}
func (*ScriptsWitness) MarshalCBOR ¶
func (s *ScriptsWitness) MarshalCBOR() ([]byte, error)
type StakeCredential ¶
type StakeCredential struct { Kind StakeCredentialType `cbor:"0,keyasint"` Data []byte `cbor:"1,keyasint"` }
func NewKeysStakeCred ¶
func NewKeysStakeCred(d []byte) StakeCredential
type StakeCredentialType ¶
type StakeCredentialType byte
const ( KeyStakeCredentialType StakeCredentialType = iota ScriptStakeCredentialype )
type StakePoint ¶
type TransactionBody ¶
type TransactionBody struct { Inputs []*Input `cbor:"0,keyasint"` Outputs []*Output `cbor:"1,keyasint"` Fee uint64 `cbor:"2,keyasint"` InvalidAfter uint32 `cbor:"3,keyasint,omitempty"` InvalidBefore uint32 `cbor:"8,keyasint,omitempty"` }
func (*TransactionBody) Bytes ¶
func (b *TransactionBody) Bytes() []byte
type Tx ¶
type Tx struct { Body *TransactionBody Witness *Witness Metadata interface{} // TODO: supports it // contains filtered or unexported fields }
func NewTx ¶
func NewTx() *Tx
NewTx creates new Tx
Example ¶
_, rawxprv, err := bech32.Decode("xprv1wq9th6qy7ej8w03cgas2lzwvzncvwaje8ek8lps6u6mwyhtpaewap0w2f9hhrpg6tvrffcvz5ecevvhfl6vnznswss96kqyncm2drut3kfps0pv0r4q3fuy6urzs52ywdpzx55muncgf283fr378hwzwp5p27ewe") if err != nil { panic(err) } rootprv, err := bip32.NewXPrv(rawxprv) if err != nil { panic(err) } rootpub, rootxpub := rootprv.PublicKey(), rootprv.XPub().Bytes() shellAddress := NewKeyedEnterpriseAddress(rootpub, Testnet) byronAddress, err := NewSimpleLegacyAddress(rootxpub) if err != nil { panic(err) } // ADA only transaction { tx := NewTx() tx.AddInputs(MustInput("2558aad25ec6b0e74009f36dc60d7fec6602ce43d603e80c9edde9dd54c78eb4", 0)) tx.AddOutputs(NewOutput(shellAddress, 9000000)).SetFee(1000000).SetInvalidAfter(832163) tx.AddKeyWitness(NewKeysWitness(rootpub, rootprv.Sign(tx.Hash()))) fmt.Println(hex.EncodeToString(tx.Bytes())) } // With Token transaction { tx := NewTx() tx.AddInputs(MustInput("9640acb862c4060ab61d0c77a18348bd22c76fd855dae12d09255b5cbebe44f3", 0)) nativeAsset := MustParseAssetId("2ad8fbdc6f18d97ce61b113301f05ff6b2a241c4e0bf5d06127d30a24f4343") output0 := NewOutput(shellAddress, 0).AddAsset(nativeAsset, 10000). SetMinAda() // you can use 0 ADA at first and set min ada at last tx.AddOutputs(output0, NewOutput(shellAddress, 2e6)). SetFee(2000000). SetInvalidAfter(832163). SetInvalidBefore(822163) witness, err := NewBootstrapWitness(byronAddress, rootxpub, rootprv.Sign(tx.Hash())) if err != nil { panic(err) } tx.AddBootstrapWitness(witness) fmt.Println(tx.ID()) }
Output: 83a400818258202558aad25ec6b0e74009f36dc60d7fec6602ce43d603e80c9edde9dd54c78eb400018182581d60c5fb57853a4a5bbb13bcd494ee0facd4e1fca33720a640664df151341a00895440021a000f4240031a000cb2a3a10081825820c6e47dceb9235ad31fec01ef3e34b02839d22fb583cd28fac7ec81ebbe653a395840e94817956d902702ed6172db8edca0193b33aba511a72e1998cc18aa492be8cffaca96c8305ffbb2836c3c04c886e23302e222b99185b87b701a40a10c50660ff6 08c1e412dc65a8220f650a396ac5ca4758d8df7ff65defb790af2437b2d84df9
func (*Tx) AddBootstrapWitness ¶
func (t *Tx) AddBootstrapWitness(k *BootstrapWitness) *Tx
AddBootstrapWitness adds witness for legacy(Byron) address
func (*Tx) AddKeyWitness ¶
func (t *Tx) AddKeyWitness(k *KeysWitness) *Tx
AddKeyWitness adds witness for Shelly address
func (*Tx) SetInvalidAfter ¶
SetInvalidAfter sets InvalidAfter for tx
func (*Tx) SetInvalidBefore ¶
SetInvalidBefore sets InvalidBefore for tx
type Witness ¶
type Witness struct { Keys []*KeysWitness `cbor:"0,keyasint,omitempty"` Scripts []*ScriptsWitness `cbor:"1,keyasint,omitempty"` Bootstrap []*BootstrapWitness `cbor:"2,keyasint,omitempty"` }