address

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

Address

GoDoc

Package address implements structs for Cardano address types.

Installation

go get github.com/jsambuo/go-cardano-serialization/address

Overview

Address handles serialization and deserilization of addresses used on the Cardano network. Currently supports:

  • Byron/Legacy Address
  • Enterprise Address
  • Base Address
  • Pointer Address
  • Reward Address

Address package also provides an Address interface and utility to load address from bech32/base58 encoded strings automatically into one of the supported address types.

Usage

Examples on how to use the address package can be found in examples

License

Package address is licensed under the Apache License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidByronAddress  = errors.New("invalid byron address")
	ErrInvalidByronChecksum = errors.New("invalid byron checksum")
)
View Source
var (
	ErrUnsupportedAddress = errors.New("invalid/unsupported address type")
)

Functions

func VariableNatDecode

func VariableNatDecode(raw []byte) (uint64, int, error)

func VariableNatEncode

func VariableNatEncode(num uint64) []byte

Types

type Address

type Address interface {
	cbor.Marshaler

	// Bytes returns raw bytes for use in tx_outputs
	Bytes() []byte

	// String returns bech32 encoded human readable string
	String() string

	// NetworkInfo returns NetworkInfo with networks network id and protocol magic
	NetworkInfo() *network.NetworkInfo
}

func NewAddress

func NewAddress(raw string) (addr Address, err error)

func NewAddressFromBytes

func NewAddressFromBytes(data []byte) (addr Address, err error)

func NewAddressFromHex

func NewAddressFromHex(hexAddr string) (addr Address, err error)

type BaseAddress

type BaseAddress struct {
	Network network.NetworkInfo
	Payment StakeCredential
	Stake   StakeCredential
}

BaseAddress contains information of the base address. A base address directly specifies the staking key that should control the stake for that address but can be used for transactions without registering the staking key in advance.

func NewBaseAddress

func NewBaseAddress(network *network.NetworkInfo, payment *StakeCredential, stake *StakeCredential) *BaseAddress

NewBaseAddress returns a pointer to a new BaseAddress given the network, payment and stake credentials.

func (*BaseAddress) Bytes

func (b *BaseAddress) Bytes() []byte

Bytes returns a length 57 byte slice represantation of the Address.

func (*BaseAddress) MarshalCBOR

func (b *BaseAddress) MarshalCBOR() ([]byte, error)

MarshalCBOR returns a cbor encoded byte slice of the base address.

func (*BaseAddress) NetworkInfo

func (b *BaseAddress) NetworkInfo() *network.NetworkInfo

NetworkInfo returns NetworkInfo{ProtocolMagigic and NetworkId}.

func (*BaseAddress) Prefix

func (b *BaseAddress) Prefix() string

Prefix returns the string prefix for the base address. Prefix `addr` for mainnet addresses and `addr_test` for testnet.

func (*BaseAddress) String

func (b *BaseAddress) String() string

String returns a bech32 encoded string of the Enterprise Address.

func (*BaseAddress) ToEnterprise

func (b *BaseAddress) ToEnterprise() (addr *EnterpriseAddress)

ToEnterprise returns the Enterprise Address from the base address. This is equivalent to removing the stake part of the base address.

func (*BaseAddress) ToReward

func (b *BaseAddress) ToReward() (addr *RewardAddress)

ToReward returns the RewardAddress from the base address. This is equivalent to removing the payment part of the base address.

type ByronAddress

type ByronAddress struct {
	Hash       []byte
	Attributes ByronAddressAttributes
	Tag        uint
}

func (*ByronAddress) Bytes

func (b *ByronAddress) Bytes() (bytes []byte)

Bytes returns byte slice represantation of the Address.

func (*ByronAddress) MarshalCBOR

func (b *ByronAddress) MarshalCBOR() (bytes []byte, err error)

MarshalCBOR returns a cbor encoded byte slice of the base address.

func (*ByronAddress) NetworkInfo

func (b *ByronAddress) NetworkInfo() (ni *network.NetworkInfo)

NetworkInfo returns NetworkInfo{ProtocolMagigic and NetworkId}.

func (*ByronAddress) Prefix

func (b *ByronAddress) Prefix() string

Pref returns the string prefix for the base address. "" for byron address since it has no prefix.

func (*ByronAddress) String

func (b *ByronAddress) String() (str string)

String returns base58 encoded byron address.

func (*ByronAddress) UnmarshalCBOR

func (b *ByronAddress) UnmarshalCBOR(data []byte) error

UnmarshalCBOR deserializes raw byron address, encoded in cbor, into a Byron Address.

type ByronAddressAttributes

type ByronAddressAttributes struct {
	Payload []byte `cbor:"1,keyasint,omitempty"`
	Network *uint8 `cbor:"2,keyasint,omitempty"`
}

type EnterpriseAddress

type EnterpriseAddress struct {
	Network network.NetworkInfo
	Payment StakeCredential
}

EnterpriseAddress contains content for enterprise addresses. Enterprise addresses carry no stake rights, so using these addresses means that you are opting out of participation in the proof-of-stake protocol.

func NewEnterpriseAddress

func NewEnterpriseAddress(network *network.NetworkInfo, payment *StakeCredential) *EnterpriseAddress

NewEnterpriseAddress returns a pointer to a new Enterprise Address given the network and payment.

func (*EnterpriseAddress) Bytes

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

Bytes returns a length 29 byte slice represantation of the Address.

func (*EnterpriseAddress) MarshalCBOR

func (e *EnterpriseAddress) MarshalCBOR() (bytes []byte, err error)

MarshalCBOR returns a cbor encoded byte slice of the enterprise address.

func (*EnterpriseAddress) NetworkInfo

func (e *EnterpriseAddress) NetworkInfo() *network.NetworkInfo

NetworkInfo returns NetworkInfo{ProtocolMagigic and NetworkId}.

func (*EnterpriseAddress) Prefix

func (e *EnterpriseAddress) Prefix() string

Prefix returns the string prefix for the Enterprise Address. Prefix `addr` for mainnet addresses and `addr_test` for testnet.

func (*EnterpriseAddress) String

func (e *EnterpriseAddress) String() string

String returns a bech32 encoded string of the Enterprise Address.

type PointerAddress

type PointerAddress struct {
	Network network.NetworkInfo
	Payment StakeCredential
	Stake   StakePointer
}

A pointer address indirectly specifies the staking key that should control the stake for the address.

func NewPointerAddress

func NewPointerAddress(net network.NetworkInfo, payment StakeCredential, stake StakePointer) *PointerAddress

NewPointerAddress returns a pointer to a new Pointer address given the network, payment and stake credentials.

func (*PointerAddress) Bytes

func (p *PointerAddress) Bytes() (bytes []byte)

Bytes retuns a byte slice representation of the pointer address.

func (*PointerAddress) MarshalCBOR

func (p *PointerAddress) MarshalCBOR() (bytes []byte, err error)

MarshalCBOR returns a cbor encoded byte slice of the enterprise address.

func (*PointerAddress) NetworkInfo

func (p *PointerAddress) NetworkInfo() *network.NetworkInfo

NetworkInfo returns NetworkInfo{ProtocolMagigic and NetworkId}.

func (*PointerAddress) Prefix

func (p *PointerAddress) Prefix() string

Prefix returns the string prefix for the base address. Prefix `addr` for mainnet addresses and `addr_test` for testnet.

func (*PointerAddress) String

func (p *PointerAddress) String() string

String returns a bech32 encoded string of the Enterprise Address.

type RewardAddress

type RewardAddress struct {
	Network network.NetworkInfo
	Stake   StakeCredential
}

RewardAddress contains content of the reward/staking address. Reward account addresses are used to distribute rewards for participating in the proof-of-stake protocol (either directly or via delegation).

func NewRewardAddress

func NewRewardAddress(net *network.NetworkInfo, stake *StakeCredential) *RewardAddress

NewRewardAddress returns a pointer to a new RewardAddress given the network and stake credentials.

func (*RewardAddress) Bytes

func (r *RewardAddress) Bytes() []byte

Bytes returns a length 29 byte slice represantation of the Address.

func (*RewardAddress) MarshalCBOR

func (r *RewardAddress) MarshalCBOR() ([]byte, error)

MarshalCBOR returns a cbor encoded byte slice of the base address.

func (*RewardAddress) NetworkInfo

func (r *RewardAddress) NetworkInfo() *network.NetworkInfo

NetworkInfo returns pointer to NetworkInfo{ProtocolMagigic and NetworkId}.

func (*RewardAddress) Prefix

func (r *RewardAddress) Prefix() string

Prefix returns the string prefix for the base address. Prefix `stake` for mainnet addresses and `stake_test` for testnet.

func (*RewardAddress) String

func (r *RewardAddress) String() string

String returns a bech32 encoded string of the reward address.

type StakeCredential

type StakeCredential struct {
	Kind    StakeCredentialType `cbor:"0,keyasint,omitempty"`
	Payload []byte              `cbor:"1,keyasint,omitempty"`
}

func NewKeyStakeCredential

func NewKeyStakeCredential(hash []byte) *StakeCredential

func NewScriptStakeCredential

func NewScriptStakeCredential(hash []byte) *StakeCredential

type StakeCredentialType

type StakeCredentialType byte
const (
	KeyStakeCredentialType StakeCredentialType = iota
	ScriptStakeCredentialType
)

type StakePointer

type StakePointer struct {
	Slot      uint64
	TxIndex   uint64
	CertIndex uint64
}

func NewPointer

func NewPointer(slot, txIndex, certIndex uint64) *StakePointer

NewPointer returns a pointer to a new StakePointer given slot, transaction index and certificate index.

Jump to

Keyboard shortcuts

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