cardano

package module
v0.0.0-...-0ad51f2 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

README

cardano-go

cardano-go is both a library for creating go applicactions that interact with the Cardano Blockchain as well as a CLI to manage Cardano Wallets [WIP].

Installation from source

Clone the repository using git clone

$ git clone https://github.com/echovl/cardano-wallet.git

Compile the source code and install the executable

$ make && sudo make install

Dependencies

For balance and transfer commands cardano-node and cardano-cli are required. You can install them using this guide https://docs.cardano.org/projects/cardano-node/en/latest/getting-started/install.html

Getting started

First create a new wallet and generate your mnemonic squence:

$ cardano-wallet new-wallet myWallet -p simplePassword
mnemonic: banner capital gift plate worth sand pass canvas pave decade pig borrow cruel lunar arena

If you already have a wallet you can restore it using a mnemonic and password:running this command:

$ cardano-wallet new-wallet restoredWallet -m=talent,risk,require,split,leave,script,panel,slight,entire,soap,chase,pill,grant,laugh,fringe -p simplePassword

You can inspect your wallets using the list-wallets command:

$ cardano-wallet list-wallets
ID              NAME      ADDRESS
wl_uu4FmZvNYG   myWallet  1

By default a new wallet is created with one payment address, you can create more addresses running the following command:

$ cardano-wallet new-address wl_uu4FmZvNYG
New address addr_test1vz8vyz6pk6hwgwqz239rcyk52e659aefa8g08amm80tq8ag9eng6q

To get all addresses run:

$ cardano-wallet list-address wallet_WGejugqca4 --testnet
PATH                      ADDRESS
m/1852'/1815'/0'/0/0      addr_test1vpfla0wgltpjwxzt52p7wkn720eact33udlq9z8xrc6cypc3c70f5

You can get your balance running:

$ cardano-wallet balance wallet_WGejugqca4 --testnet
ASSET                     AMOUNT
Lovelace                  1000000000

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ShelleyProtocol = ProtocolParams{
	MinimumUtxoValue: 1000000,
	MinFeeA:          44,
	MinFeeB:          155381,
}

Functions

func CalculateFee

func CalculateFee(tx *Transaction, protocol ProtocolParams) uint64

func DecodeAddress

func DecodeAddress(data []byte) (Address, Address, error)

func LiveTTL

func LiveTTL() uint64

func ParseUint64

func ParseUint64(s string) (uint64, error)

Types

type Address

type Address string

Address is the bech32 representation of a cardano address

func Bech32ToAddress

func Bech32ToAddress(addr string) (Address, error)

Bech32ToAddress creates an Address from a bech32 encoded string.

func BytesToAddress

func BytesToAddress(addr []byte, network Network) (Address, error)

BytesToAddress creates an Address from a byte slice.

func NewEnterpriseAddress

func NewEnterpriseAddress(xvk crypto.ExtendedVerificationKey, network Network) Address

func (*Address) Bytes

func (addr *Address) Bytes() []byte

Bytes returns the byte slice representation of the address.

type Certificate

type Certificate struct{}

TODO: This should a cbor array with one element:

 stake_registration
	stake_deregistration
	stake_delegation
	pool_registration
	pool_retirement
	genesis_key_delegation
	move_instantaneous_rewards_cert

type Client

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

Client provides a clean interface for creating, saving and deleting Wallets.

func NewClient

func NewClient(opts ...Options) *Client

NewClient builds a new Client using cardano-cli as the default connection to the Blockhain.

It uses BadgerDB as the default Wallet storage.

func (*Client) Close

func (c *Client) Close()

Close closes all the resources used by the Client.

func (*Client) CreateWallet

func (c *Client) CreateWallet(name, password string) (*Wallet, string, error)

CreateWallet creates a new Wallet using a secure entropy and password, returning a Wallet with its corresponding 24 word mnemonic

func (*Client) DeleteWallet

func (c *Client) DeleteWallet(id string) error

DeleteWallet removes a Wallet with the given id from the Client's storage.

func (*Client) RestoreWallet

func (c *Client) RestoreWallet(name, password, mnemonic string) (*Wallet, error)

RestoreWallet restores a Wallet from a mnemonic and password.

func (*Client) SaveWallet

func (c *Client) SaveWallet(w *Wallet) error

SaveWallet saves a Wallet in the Client's storage.

func (*Client) Wallet

func (c *Client) Wallet(id string) (*Wallet, error)

Wallet returns a Wallet with the given id from the Client's storage.

func (*Client) Wallets

func (c *Client) Wallets() ([]*Wallet, error)

Wallets returns the list of Wallets currently saved in the Client's storage.

type DB

type DB interface {
	SaveWallet(*Wallet) error
	GetWallets() ([]*Wallet, error)
	DeleteWallet(string) error
	Close()
}

type Network

type Network byte
const (
	Testnet Network = 0
	Mainnet Network = 1
)

type NodeTip

type NodeTip struct {
	Epoch uint64
	Block uint64
	Slot  uint64
}

type Options

type Options interface {
	// contains filtered or unexported methods
}

func WithDB

func WithDB(db DB) Options

func WithNode

func WithNode(node cardanoNode) Options

func WithSocket

func WithSocket(socketPath string) Options

type ProtocolParams

type ProtocolParams struct {
	MinimumUtxoValue uint64
	PoolDeposit      uint64
	KeyDeposit       uint64
	MinFeeA          uint64
	MinFeeB          uint64
}

type TXBodyBuilder

type TXBodyBuilder struct {
	Protocol ProtocolParams
	TTL      uint64
}

func (TXBodyBuilder) Build

func (builder TXBodyBuilder) Build(receiver Address, pickedUtxos []Utxo, amount uint64, change Address) (*TransactionBody, error)

type TXBuilder

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

func NewTxBuilder

func NewTxBuilder(protocol ProtocolParams) *TXBuilder

func (*TXBuilder) AddFee

func (builder *TXBuilder) AddFee(address Address) error

This assumes that the builder inputs and outputs are defined

func (*TXBuilder) AddInput

func (builder *TXBuilder) AddInput(xvk crypto.ExtendedVerificationKey, txId TransactionID, index, amount uint64)

func (*TXBuilder) AddInputWithoutSig

func (builder *TXBuilder) AddInputWithoutSig(txId TransactionID, index, amount uint64)

func (*TXBuilder) AddOutput

func (builder *TXBuilder) AddOutput(address Address, amount uint64)

func (*TXBuilder) Build

func (builder *TXBuilder) Build() Transaction

func (*TXBuilder) SetFee

func (builder *TXBuilder) SetFee(fee uint64)

func (*TXBuilder) SetTtl

func (builder *TXBuilder) SetTtl(ttl uint64)

func (*TXBuilder) Sign

func (builder *TXBuilder) Sign(xsk crypto.ExtendedSigningKey)

type TXBuilderInput

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

type TXBuilderOutput

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

type Transaction

type Transaction struct {
	Body       TransactionBody
	WitnessSet TransactionWitnessSet
	Metadata   *transactionMetadata // or null
	// contains filtered or unexported fields
}

func DecodeTransaction

func DecodeTransaction(cborHex string) (*Transaction, error)

func (*Transaction) Bytes

func (tx *Transaction) Bytes() []byte

func (*Transaction) CborHex

func (tx *Transaction) CborHex() string

func (*Transaction) ID

func (tx *Transaction) ID() TransactionID

type TransactionBody

type TransactionBody struct {
	Inputs       []TransactionInput  `cbor:"0,keyasint"`
	Outputs      []TransactionOutput `cbor:"1,keyasint"`
	Fee          uint64              `cbor:"2,keyasint"`
	Ttl          uint64              `cbor:"3,keyasint"`
	Certificates []Certificate       `cbor:"4,keyasint,omitempty"` // Omit for now
	Withdrawals  *uint               `cbor:"5,keyasint,omitempty"` // Omit for now
	Update       *uint               `cbor:"6,keyasint,omitempty"` // Omit for now
	MetadataHash *uint               `cbor:"7,keyasint,omitempty"` // Omit for now
}

func (*TransactionBody) AddSignatures

func (body *TransactionBody) AddSignatures(publicKeys [][]byte, signatures [][]byte) (*Transaction, error)

func (*TransactionBody) Bytes

func (body *TransactionBody) Bytes() []byte

func (*TransactionBody) ID

func (body *TransactionBody) ID() TransactionID

type TransactionID

type TransactionID string

func (TransactionID) Bytes

func (id TransactionID) Bytes() []byte

type TransactionInput

type TransactionInput struct {
	ID    []byte // HashKey 32 bytes
	Index uint64
	// contains filtered or unexported fields
}

type TransactionOutput

type TransactionOutput struct {
	Address []byte
	Amount  uint64
	// contains filtered or unexported fields
}

type TransactionWitnessSet

type TransactionWitnessSet struct {
	VKeyWitnessSet []VKeyWitness `cbor:"0,keyasint,omitempty"`
}

type Utxo

type Utxo struct {
	Address Address
	TxId    TransactionID
	Amount  uint64
	Index   uint64
}

type VKeyWitness

type VKeyWitness struct {
	VKey      []byte // ed25519 public key
	Signature []byte // ed25519 signature
	// contains filtered or unexported fields
}

type Wallet

type Wallet struct {
	ID   string
	Name string
	// contains filtered or unexported fields
}

func (*Wallet) AddAddress

func (w *Wallet) AddAddress() Address

AddAddress generates a new payment address and adds it to the wallet.

func (*Wallet) Addresses

func (w *Wallet) Addresses() []Address

Addresses returns all wallet's addresss.

func (*Wallet) Balance

func (w *Wallet) Balance() (uint64, error)

Balance returns the total lovelace amount of the wallet.

func (*Wallet) SetNetwork

func (w *Wallet) SetNetwork(net Network)

func (*Wallet) Transfer

func (w *Wallet) Transfer(receiver Address, amount uint64) error

Transfer sends an amount of lovelace to the receiver address TODO: remove hardcoded protocol parameters, these parameters must be obtained using the cardano node

Directories

Path Synopsis
cli
cmd

Jump to

Keyboard shortcuts

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