cardano

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 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 NewEntropy = func(bitSize int) []byte {
	entropy, _ := bip39.NewEntropy(bitSize)
	return entropy
}

Functions

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 (*Address) Bytes

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

Bytes returns the byte slice representation of the address.

type CardanoCli added in v1.0.2

type CardanoCli struct {
	SocketPath string
}

func (*CardanoCli) QueryTip added in v1.0.2

func (cli *CardanoCli) QueryTip() (NodeTip, error)

TODO: add ability to use mainnet and testnet

func (*CardanoCli) QueryUtxos added in v1.0.2

func (cli *CardanoCli) QueryUtxos(address Address) ([]Utxo, error)

TODO: add ability to use mainnet and testnet

func (*CardanoCli) SubmitTx added in v1.0.2

func (cli *CardanoCli) SubmitTx(tx transaction) error

TODO: add ability to use mainnet and testnet

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 RpcNode added in v1.0.2

type RpcNode struct {
	Url string
}

func NewRpcNode added in v1.0.2

func NewRpcNode(url string) *RpcNode

func (*RpcNode) QueryTip added in v1.0.2

func (nd *RpcNode) QueryTip() (NodeTip, error)

func (*RpcNode) QueryUtxos added in v1.0.2

func (nd *RpcNode) QueryUtxos(Address) ([]Utxo, error)

func (*RpcNode) SubmitTx added in v1.0.2

func (nd *RpcNode) SubmitTx(transaction) error

type Utxo

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

func NewUtxo added in v1.0.2

func NewUtxo(txid string, address string, index uint64, amount uint64) (utxo Utxo, err error)

type Wallet

type Wallet struct {
	ID    string
	Name  string
	Keys  map[string]crypto.ExtendedSigningKey
	Skeys []crypto.ExtendedSigningKey

	Utxos []Utxo
	Tip   NodeTip
	// contains filtered or unexported fields
}

func NewWallet

func NewWallet(name, password string, entropy []byte) *Wallet

func (*Wallet) AddAddress

func (w *Wallet) AddAddress() Address

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

func (*Wallet) AddressIndex added in v1.0.2

func (w *Wallet) AddressIndex(idx int) (Address, error)

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) GenAddress added in v1.0.2

func (w *Wallet) GenAddress(idx int) (addr Address, pri string, err error)

func (*Wallet) SetKey

func (w *Wallet) SetKey(key string) error

func (*Wallet) SetNetwork

func (w *Wallet) SetNetwork(net Network)

func (*Wallet) SetUtxos

func (w *Wallet) SetUtxos(utxos []Utxo)

func (*Wallet) Transfer

func (w *Wallet) Transfer(receiver Address, amount uint64, changeAddress Address) (tx *transaction, err 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