Documentation
¶
Overview ¶
Package cardano-go is a library for the Cardano Blockchain.
Getting started ¶
The best way to get started working with cardano-go is to use `go get` to add the library.
go get github.com/echovl/cardano-go go get github.com/echovl/cardano-go/node go get github.com/echovl/cardano-go/tx
Hello cardano-go ¶
This example shows how you can use cardano-go to query UTXOs.
package main
import (
"fmt"
"github.com/echovl/cardano-go/node/blockfrost"
"github.com/echovl/cardano-go/types"
)
func main() {
addr, err := types.NewAddress("addr1v9c7flddz5nqj448t78h5mdgau8p9ee24m7n62g2s48akkcjzfhw3")
if err != nil {
panic(err)
}
node := blockfrost.NewNode(types.Mainnet, "project-id")
utxos, err := node.UTXOs(addr)
if err != nil {
panic(err)
}
fmt.Println(utxos)
}
Index ¶
- Constants
- func Blake224Hash(b []byte) ([]byte, error)
- type AddrKeyHash
- type Address
- func NewAddress(bech string) (Address, error)
- func NewAddressFromBytes(bytes []byte) (Address, error)
- func NewBaseAddress(network Network, payment StakeCredential, stake StakeCredential) (Address, error)
- func NewEnterpriseAddress(network Network, payment StakeCredential) (Address, error)
- func NewPointerAddress(network Network, payment StakeCredential, ptr Pointer) (Address, error)
- type AddressType
- type AssetName
- type Assets
- type AuxiliaryData
- type BigNum
- type Certificate
- type CertificateType
- type Coin
- type Hash28
- type Hash32
- type Metadata
- type Mint
- func (ma *Mint) AssetsLength() uint
- func (m *Mint) Get(policyID PolicyID) *MintAssets
- func (m *Mint) Keys() []PolicyID
- func (ma *Mint) MarshalCBOR() ([]byte, error)
- func (m *Mint) MultiAsset() *MultiAsset
- func (ma *Mint) NumAssets() uint
- func (ma *Mint) NumPIDs() uint
- func (m *Mint) Set(policyID PolicyID, assets *MintAssets) *Mint
- type MintAssets
- type MultiAsset
- func (ma *MultiAsset) AssetsLength() uint
- func (ma *MultiAsset) Get(policyID PolicyID) *Assets
- func (ma *MultiAsset) Keys() []PolicyID
- func (ma *MultiAsset) MarshalCBOR() ([]byte, error)
- func (ma *MultiAsset) NumAssets() uint
- func (ma *MultiAsset) NumPIDs() uint
- func (ma *MultiAsset) Set(policyID PolicyID, assets *Assets) *MultiAsset
- type NativeScript
- type NativeScriptType
- type Network
- type Node
- type NodeTip
- type Pointer
- type PolicyID
- type PoolKeyHash
- type PoolMetadata
- type ProtocolParams
- type ProtocolVersion
- type Rational
- type Relay
- type RelayType
- type ScriptHashNamespace
- type StakeCredential
- type StakeCredentialType
- type String
- type Tx
- type TxBody
- type TxBuilder
- func (tb *TxBuilder) AddAuxiliaryData(data *AuxiliaryData)
- func (tb *TxBuilder) AddCertificate(cert Certificate)
- func (tb *TxBuilder) AddChangeIfNeeded(changeAddr Address) error
- func (tb *TxBuilder) AddInputs(inputs ...*TxInput)
- func (tb *TxBuilder) AddNativeScript(script NativeScript)
- func (tb *TxBuilder) AddOutputs(outputs ...*TxOutput)
- func (tb *TxBuilder) Build() (*Tx, error)
- func (tb *TxBuilder) MinCoinsForTxOut(txOut *TxOutput) Coin
- func (tb *TxBuilder) MinFee() (Coin, error)
- func (tb *TxBuilder) Mint(asset *Mint)
- func (tb *TxBuilder) SetFee(fee Coin)
- func (tb *TxBuilder) SetTTL(ttl uint64)
- func (tb *TxBuilder) Sign(privateKeys ...crypto.PrvKey)
- type TxInput
- type TxOutput
- type UTxO
- type Uint64
- type UnitInterval
- type VKeyWitness
- type Value
- type WitnessSet
Constants ¶
const ( SingleHostAddr RelayType = 0 SingleHostName = 1 MultiHostName = 2 )
const (
ProtocolMagic = 1097911063
)
Variables ¶
This section is empty.
Functions ¶
func Blake224Hash ¶ added in v0.1.9
Types ¶
type AddrKeyHash ¶
type AddrKeyHash = Hash28
type Address ¶
type Address struct {
Network Network
Type AddressType
Pointer Pointer
Payment StakeCredential
Stake StakeCredential
}
Address represents a cardano address.
func NewAddress ¶
NewAddress creates an Address from a bech32 encoded string.
func NewAddressFromBytes ¶
NewAddressFromBytes creates an Address from bytes.
func NewBaseAddress ¶
func NewBaseAddress(network Network, payment StakeCredential, stake StakeCredential) (Address, error)
func NewEnterpriseAddress ¶
func NewEnterpriseAddress(network Network, payment StakeCredential) (Address, error)
func NewPointerAddress ¶
func NewPointerAddress(network Network, payment StakeCredential, ptr Pointer) (Address, error)
func (*Address) MarshalCBOR ¶
MarshalCBOR implements cbor.Marshaler.
func (*Address) UnmarshalCBOR ¶
UnmarshalCBOR implements cbor.Unmarshaler.
type AddressType ¶
type AddressType byte
const ( Base AddressType = 0x00 Ptr AddressType = 0x04 Enterprise AddressType = 0x06 )
type AssetName ¶ added in v0.1.9
type AssetName struct {
// contains filtered or unexported fields
}
func NewAssetName ¶ added in v0.1.9
type Assets ¶ added in v0.1.9
type Assets struct {
// contains filtered or unexported fields
}
func (*Assets) MarshalCBOR ¶ added in v0.1.9
MarshalCBOR implements cbor.Marshaler
type AuxiliaryData ¶
type AuxiliaryData struct {
Metadata Metadata `cbor:"0,keyasint,omitempty"`
NativeScripts interface{} `cbor:"1,keyasint,omitempty"`
PlutusScripts interface{} `cbor:"2,keyasint,omitempty"`
}
func (*AuxiliaryData) MarshalCBOR ¶
func (d *AuxiliaryData) MarshalCBOR() ([]byte, error)
MarshalCBOR implements cbor.Marshaler
func (*AuxiliaryData) UnmarshalCBOR ¶
func (d *AuxiliaryData) UnmarshalCBOR(data []byte) error
UnmarshalCBOR implements cbor.Unmarshaler
type Certificate ¶
type Certificate struct {
Type CertificateType
// Common fields
StakeCredential StakeCredential
PoolKeyHash PoolKeyHash
VrfKeyHash Hash32
// Pool related fields
Operator PoolKeyHash
Pledge Coin
Margin UnitInterval
RewardAccount Address
Owners []AddrKeyHash
Relays []Relay
PoolMetadata *PoolMetadata // or null
Epoch uint64
// Genesis fields
GenesisHash Hash28
GenesisDelegateHash Hash28
}
TODO: MoveInstantaneousRewardsCert requires a map with StakeCredential as a key
func NewStakeDelegationCertificate ¶ added in v0.1.8
func NewStakeDelegationCertificate(stakeKey crypto.PubKey, poolKeyHash Hash28) (Certificate, error)
func NewStakeDeregistrationCertificate ¶ added in v0.1.8
func NewStakeDeregistrationCertificate(stakeKey crypto.PubKey) (Certificate, error)
func NewStakeRegistrationCertificate ¶ added in v0.1.8
func NewStakeRegistrationCertificate(stakeKey crypto.PubKey) (Certificate, error)
func (*Certificate) MarshalCBOR ¶
func (c *Certificate) MarshalCBOR() ([]byte, error)
MarshalCBOR implements cbor.Marshaler.
func (*Certificate) UnmarshalCBOR ¶
func (c *Certificate) UnmarshalCBOR(data []byte) error
UnmarshalCBOR implements cbor.Unmarshaler.
type CertificateType ¶
type CertificateType uint
const ( StakeRegistration CertificateType = iota StakeDeregistration StakeDelegation PoolRegistration PoolRetirement GenesisKeyDelegation MoveInstantaneousRewards )
type Hash28 ¶
type Hash28 []byte
type Hash32 ¶
type Hash32 []byte
type Mint ¶ added in v0.1.10
type Mint struct {
// contains filtered or unexported fields
}
func (*Mint) AssetsLength ¶ added in v0.1.10
func (*Mint) Get ¶ added in v0.1.10
func (m *Mint) Get(policyID PolicyID) *MintAssets
func (*Mint) MarshalCBOR ¶ added in v0.1.10
MarshalCBOR implements cbor.Marshaler
func (*Mint) MultiAsset ¶ added in v0.1.10
func (m *Mint) MultiAsset() *MultiAsset
type MintAssets ¶ added in v0.1.10
type MintAssets struct {
// contains filtered or unexported fields
}
func NewMintAssets ¶ added in v0.1.10
func NewMintAssets() *MintAssets
func (*MintAssets) Keys ¶ added in v0.1.10
func (a *MintAssets) Keys() []AssetName
func (*MintAssets) MarshalCBOR ¶ added in v0.1.10
func (a *MintAssets) MarshalCBOR() ([]byte, error)
MarshalCBOR implements cbor.Marshaler
func (*MintAssets) Set ¶ added in v0.1.10
func (a *MintAssets) Set(name AssetName, val *big.Int) *MintAssets
type MultiAsset ¶ added in v0.1.9
type MultiAsset struct {
// contains filtered or unexported fields
}
func NewMultiAsset ¶ added in v0.1.9
func NewMultiAsset() *MultiAsset
func (*MultiAsset) AssetsLength ¶ added in v0.1.9
func (ma *MultiAsset) AssetsLength() uint
func (*MultiAsset) Get ¶ added in v0.1.9
func (ma *MultiAsset) Get(policyID PolicyID) *Assets
func (*MultiAsset) Keys ¶ added in v0.1.9
func (ma *MultiAsset) Keys() []PolicyID
func (*MultiAsset) MarshalCBOR ¶ added in v0.1.9
func (ma *MultiAsset) MarshalCBOR() ([]byte, error)
MarshalCBOR implements cbor.Marshaler
func (*MultiAsset) NumAssets ¶ added in v0.1.9
func (ma *MultiAsset) NumAssets() uint
func (*MultiAsset) NumPIDs ¶ added in v0.1.9
func (ma *MultiAsset) NumPIDs() uint
func (*MultiAsset) Set ¶ added in v0.1.9
func (ma *MultiAsset) Set(policyID PolicyID, assets *Assets) *MultiAsset
type NativeScript ¶ added in v0.1.9
type NativeScript struct {
Type NativeScriptType
KeyHash AddrKeyHash
N uint64
Scripts []NativeScript
IntervalValue uint64
}
func NewScriptPubKey ¶ added in v0.1.9
func NewScriptPubKey(publicKey crypto.PubKey) (NativeScript, error)
func (*NativeScript) Bytes ¶ added in v0.1.9
func (ns *NativeScript) Bytes() ([]byte, error)
Bytes returns the CBOR encoding of the script as bytes.
func (*NativeScript) Hash ¶ added in v0.1.9
func (ns *NativeScript) Hash() (Hash28, error)
Hash returns the script hash using blake2b224.
func (*NativeScript) MarshalCBOR ¶ added in v0.1.9
func (ns *NativeScript) MarshalCBOR() ([]byte, error)
MarshalCBOR implements cbor.Marshaler.
type NativeScriptType ¶ added in v0.1.9
type NativeScriptType uint64
const ( ScriptPubKey NativeScriptType = iota ScriptAll ScriptAny ScriptNofK ScriptInvalidBefore ScriptInvalidAfter )
type Node ¶
type Node interface {
// UTxOs returns a list of unspent transaction outputs for a given address
UTxOs(Address) ([]UTxO, error)
// Tip returns the node's current tip
Tip() (*NodeTip, error)
// SubmitTx submits a transaction to the node using cbor encoding
SubmitTx(*Tx) (*Hash32, error)
// ProtocolParams returns the Node's Protocol Parameters
ProtocolParams() (*ProtocolParams, error)
// Network returns the node's current network type
Network() Network
}
Node is the interface required for a Cardano backend/node. A backend/node is used to interact with the Cardano Blockchain, sending transactions and fetching state.
type PolicyID ¶ added in v0.1.9
type PolicyID struct {
// contains filtered or unexported fields
}
func NewPolicyID ¶ added in v0.1.9
func NewPolicyID(script NativeScript) (PolicyID, error)
func NewPolicyIDFromHash ¶ added in v0.1.9
type PoolKeyHash ¶
type PoolKeyHash = Hash28
type PoolMetadata ¶
type ProtocolParams ¶
type ProtocolParams struct {
MinFeeA Coin
MinFeeB Coin
MaxBlockBodySize uint
MaxTxSize uint
MaxBlockHeaderSize uint
KeyDeposit Coin
PoolDeposit Coin
MaxEpoch uint
NOpt uint
PoolPledgeInfluence Rational
ExpansionRate UnitInterval
TreasuryGrowthRate UnitInterval
D UnitInterval
ExtraEntropy []byte
ProtocolVersion ProtocolVersion
MinPoolCost Coin
CoinsPerUTXOWord Coin
CostModels interface{}
ExecutionCosts interface{}
MaxTxExUnits interface{}
MaxBlockTxExUnits interface{}
MaxValueSize uint
CollateralPercentage uint
MaxCollateralInputs uint
}
type ProtocolVersion ¶ added in v0.1.8
type Rational ¶ added in v0.1.8
func (*Rational) MarshalCBOR ¶ added in v0.1.8
MarshalCBOR implements cbor.Marshaler
func (*Rational) UnmarshalCBOR ¶ added in v0.1.8
UnmarshalCBOR implements cbor.Unmarshaler
type Relay ¶
func (*Relay) MarshalCBOR ¶
MarshalCBOR implements cbor.Marshaler.
func (*Relay) UnmarshalCBOR ¶
UnmarshalCBOR implements cbor.Unmarshaler.
type ScriptHashNamespace ¶ added in v0.1.9
type ScriptHashNamespace uint8
const ( NativeScriptNamespace ScriptHashNamespace = iota PlutusScriptNamespace )
type StakeCredential ¶
type StakeCredential struct {
Type StakeCredentialType
KeyHash AddrKeyHash
ScriptHash Hash28
}
func NewKeyCredential ¶ added in v0.1.8
func NewKeyCredential(publicKey crypto.PubKey) (StakeCredential, error)
func NewScriptCredential ¶
func NewScriptCredential(script []byte) (StakeCredential, error)
func (*StakeCredential) Equal ¶ added in v0.1.9
func (s *StakeCredential) Equal(rhs StakeCredential) bool
func (*StakeCredential) Hash ¶
func (s *StakeCredential) Hash() Hash28
func (*StakeCredential) MarshalCBOR ¶
func (s *StakeCredential) MarshalCBOR() ([]byte, error)
MarshalCBOR implements cbor.Marshaler.
func (*StakeCredential) UnmarshalCBOR ¶
func (s *StakeCredential) UnmarshalCBOR(data []byte) error
UnmarshalCBOR implements cbor.Unmarshaler.
type StakeCredentialType ¶
type StakeCredentialType uint64
const ( KeyCredential StakeCredentialType = iota ScriptCredential )
type Tx ¶
type Tx struct {
Body TxBody
WitnessSet WitnessSet
IsValid bool
AuxiliaryData *AuxiliaryData // or null
// contains filtered or unexported fields
}
type TxBody ¶
type TxBody struct {
Inputs []*TxInput `cbor:"0,keyasint"`
Outputs []*TxOutput `cbor:"1,keyasint"`
Fee Coin `cbor:"2,keyasint"`
// Optionals
TTL Uint64 `cbor:"3,keyasint,omitempty"`
Certificates []Certificate `cbor:"4,keyasint,omitempty"`
Withdrawals interface{} `cbor:"5,keyasint,omitempty"` // unsupported
Update interface{} `cbor:"6,keyasint,omitempty"` // unsupported
AuxiliaryDataHash *Hash32 `cbor:"7,keyasint,omitempty"`
ValidityIntervalStart Uint64 `cbor:"8,keyasint,omitempty"`
Mint *Mint `cbor:"9,keyasint,omitempty"`
ScriptDataHash *Hash32 `cbor:"10,keyasint,omitempty"`
Collateral []TxInput `cbor:"11,keyasint,omitempty"`
RequiredSigners []AddrKeyHash `cbor:"12,keyasint,omitempty"`
NetworkID Uint64 `cbor:"13,keyasint,omitempty"`
}
type TxBuilder ¶
type TxBuilder struct {
// contains filtered or unexported fields
}
func NewTxBuilder ¶
func NewTxBuilder(protocol *ProtocolParams) *TxBuilder
NewTxBuilder returns a new instance of TxBuilder.
func (*TxBuilder) AddAuxiliaryData ¶
func (tb *TxBuilder) AddAuxiliaryData(data *AuxiliaryData)
AddAuxiliaryData adds auxiliary data to the transaction.
func (*TxBuilder) AddCertificate ¶ added in v0.1.8
func (tb *TxBuilder) AddCertificate(cert Certificate)
AddCertificate adds a certificate to the transaction.
func (*TxBuilder) AddChangeIfNeeded ¶
AddChangeIfNeeded calculates the required fee for the transaction and adds an aditional output for the change if there is any. This assumes that the inputs-outputs are defined and signing keys are present.
func (*TxBuilder) AddNativeScript ¶ added in v0.1.9
func (tb *TxBuilder) AddNativeScript(script NativeScript)
AddNativeScript adds a native script to the transaction.
func (*TxBuilder) AddOutputs ¶
AddOutputs adds outputs to the transaction.
func (*TxBuilder) Build ¶
Build creates a new transaction using the inputs, outputs and keys provided.
func (*TxBuilder) MinCoinsForTxOut ¶ added in v0.1.12
MinCoinsForTxOut computes the minimal amount of coins required for a given transaction output.
func (*TxBuilder) MinFee ¶
MinFee computes the minimal fee required for the transaction. This assumes that the inputs-outputs are defined and signing keys are present.
type TxInput ¶
type TxOutput ¶
func NewTxOutput ¶
NewTxOutput creates a new instance of TxOutput
type UnitInterval ¶
type UnitInterval = Rational
type VKeyWitness ¶
type Value ¶ added in v0.1.9
type Value struct {
Coin Coin
MultiAsset *MultiAsset
}
func NewValueWithAssets ¶ added in v0.1.9
func NewValueWithAssets(coin Coin, assets *MultiAsset) *Value
func (*Value) Cmp ¶ added in v0.1.9
Compares and returns
-1 if v < rhs 0 if v == rhs 1 if v > rhs 2 if not comparable
func (*Value) MarshalCBOR ¶ added in v0.1.9
MarshalCBOR implements cbor.Marshaler
type WitnessSet ¶
type WitnessSet struct {
VKeyWitnessSet []VKeyWitness `cbor:"0,keyasint,omitempty"`
Scripts []NativeScript `cbor:"1,keyasint,omitempty"`
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
bech32
https://github.com/decred/dcrd/tree/master/bech32
|
https://github.com/decred/dcrd/tree/master/bech32 |
|
cbor
Package cbor is a modern CBOR codec (RFC 8949 & RFC 7049) with CBOR tags, Go struct tags (toarray/keyasint/omitempty), Core Deterministic Encoding, CTAP2, Canonical CBOR, float64->32->16, and duplicate map key detection.
|
Package cbor is a modern CBOR codec (RFC 8949 & RFC 7049) with CBOR tags, Go struct tags (toarray/keyasint/omitempty), Core Deterministic Encoding, CTAP2, Canonical CBOR, float64->32->16, and duplicate map key detection. |