utxo

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: GPL-3.0 Imports: 15 Imported by: 0

README

UTXO module

Birth UTXO from account funds.

regcli tx utxo birth 100wire --from alice --chain-id=wireline

Pay to an address from the UTXO (Account Output).

# Note the outpoint hash.
regcli query utxo ls-account-outputs --chain-id=wireline

# Sign but don't broadcast.
regcli tx utxo pay --from alice --chain-id=wireline $(regcli keys show alice --address) $(regcli keys show bob --address) 40 60 A447DEF319B76E111FA557BD6777B86486DAF180973A7842FB25D98A1891AC24 x CAFE --sign-only

# Broadcast with the signature from the previous step.
regcli tx utxo pay --from alice --chain-id=wireline $(regcli keys show alice --address) $(regcli keys show bob --address) 40 60 A447DEF319B76E111FA557BD6777B86486DAF180973A7842FB25D98A1891AC24 x 8AA8B6335F9FB51BA798EBB44B0B4CF25CA279A77C79D306AD4FC34B73406356024B8390F6C0EDD16ED62BB6336526FFAC088D003FE9B9C4A64935FB4B3FBAC8

Pay to an address from the newly generated UTXOs.

# Sign offline.
regcli tx utxo pay --from bob --chain-id=wireline $(regcli keys show bob --address) $(regcli keys show alice --address) 10 30 FD1B20785812C1D1D8B776DB424ED79C8CD5A68AC94ED0C26AA8E191A78522CD 0 CAFE --sign-only

# Broadcast with signature from previous step.
regcli tx utxo pay --from bob --chain-id=wireline $(regcli keys show bob --address) $(regcli keys show alice --address) 10 30 FD1B20785812C1D1D8B776DB424ED79C8CD5A68AC94ED0C26AA8E191A78522CD 0 5A8350C473BBC066A9B87F715408BC57EFB8868B816FBF43E262DCC1EB6996A533E5E270C3D56CF507AF65A2864DCDB74275BFA42FF9DF1E62F0CC529C026644

# Sign only.
regcli tx utxo pay --from alice --chain-id=wireline $(regcli keys show alice --address) $(regcli keys show bob --address) 40 20 FD1B20785812C1D1D8B776DB424ED79C8CD5A68AC94ED0C26AA8E191A78522CD 1 CAFE --sign-only

# Broadcast with signature from previous step.
# Note: Anyone can broadcast the Cosmos SDK transaction. It's the witness/signature in the payload Tx that counts.
regcli tx utxo pay --from bob --chain-id=wireline $(regcli keys show alice --address) $(regcli keys show bob --address) 40 20 FD1B20785812C1D1D8B776DB424ED79C8CD5A68AC94ED0C26AA8E191A78522CD 1 B3EDC33220D37BC477758068471E1E23F5417E473F6C3194C6EE2EAF9A5FAA7E59B0BFE2DD1A5784F866715453DC2CE40C30F065E9FE6BC18A5B997E998FE8A4

List UTXO/Account Outputs.

regcli query utxo ls-account-outputs --chain-id=wireline
regcli query utxo ls --chain-id=wireline

List transactions.

regcli query utxo ls-tx --chain-id=wireline
regcli query utxo get-tx --chain-id=wireline 40154BD90424E96506B172489DC569E2657ECD7A5F145E6D8A1BE5B1F062C2FE

View wallet balance and UTXOs.

regcli query utxo balance --chain-id=wireline $(regcli keys show alice --address)
regcli query utxo balance --chain-id=wireline $(regcli keys show bob --address)

Generate transaction graph.

regcli query utxo graph --chain-id=wireline | dot -Tpng  > test.png && eog test.png

Documentation

Index

Constants

View Source
const (
	ListAccOutput = "ls-account-outputs"
	ListUtxo      = "ls"
	ListTx        = "ls-tx"
	GetTx         = "get-tx"
	GetBalance    = "balance"
	GetGraph      = "graph"
)

Endpoints supported by the Querier.

View Source
const LabelLength int = 8

LabelLength is leading number of chars from the hash used in the dot graph.

View Source
const OutPointAccountBirth = -1

OutPointAccountBirth indicates Hash refers to an account based output birth record.

Variables

This section is empty.

Functions

func AccOutLabel

func AccOutLabel(accOut AccOutput) string

AccOutLabel returns the label for an account output.

func AccOutNode

func AccOutNode(g *dot.Graph, accOut AccOutput) dot.Node

AccOutNode creates a node for an account output.

func GenTxHash

func GenTxHash(cdc *codec.Codec, tx Tx) []byte

GenTxHash generates a transaction hash.

func GetOutPointKey

func GetOutPointKey(op OutPoint) string

GetOutPointKey returns the key used in the KVStore for the given OutPoint.

func GetTxOutValue

func GetTxOutValue(outputs []TxOut) uint64

GetTxOutValue returns the sum of the output values.

func GetTxSignature

func GetTxSignature(cdc *codec.Codec, tx Tx, name string) ([]byte, error)

GetTxSignature returns a cryptographic signature for a transaction.

func NewHandler

func NewHandler(keeper Keeper) sdk.Handler

NewHandler returns a handler for "utxo" type messages.

func NewQuerier

func NewQuerier(keeper Keeper) sdk.Querier

NewQuerier is the module level router for state queries

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec registers concrete types on the Amino codec.

func SortTxInputs

func SortTxInputs(tx *Tx)

SortTxInputs sorts transaction inputs (canonical ordering).

func SortTxOutputs

func SortTxOutputs(tx *Tx)

SortTxOutputs sorts transaction outputs (canonical ordering).

func TxInLabel

func TxInLabel(txIn TxIn) string

TxInLabel returns the edge label for a transaction input.

func TxInNodeID

func TxInNodeID(txID Hash, in TxIn) string

TxInNodeID generates a dot graph ID for a Tx input.

func TxNode

func TxNode(g *dot.Graph, txNodeID Hash, tx Tx) dot.Node

TxNode creates a node for a transaction.

func TxNodeLabel

func TxNodeLabel(txID Hash) string

TxNodeLabel returns the node label for a transaction.

func TxOutLabel

func TxOutLabel(txOutIndex int, txOut TxOut) string

TxOutLabel returns the label for a transaction output.

func UnspentOutputNode

func UnspentOutputNode(g *dot.Graph, utxo OutPoint) dot.Node

UnspentOutputNode creates a node for an UTXO.

Types

type AccOutput

type AccOutput struct {
	ID      Hash
	Value   uint64
	Address sdk.AccAddress
	Block   int64
}

AccOutput represents an account based output birth record.

func GenAccOutput

func GenAccOutput(ctx sdk.Context, keeper Keeper, msg MsgBirthAccOutput) (AccOutput, sdk.Error)

GenAccOutput creates an AccOutput from MsgBirthAccOutput info.

type Hash

type Hash []byte

Hash represents a transaction or account output ID.

func (Hash) MarshalJSON

func (h Hash) MarshalJSON() ([]byte, error)

MarshalJSON marshals to JSON using Bech32.

func (Hash) String

func (h Hash) String() string

String implements the Stringer interface.

type Keeper

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

Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine.

func NewKeeper

func NewKeeper(accountKeeper auth.AccountKeeper, coinKeeper bank.Keeper, accUtxoStoreKey sdk.StoreKey, utxoStoreKey sdk.StoreKey, txStoreKey sdk.StoreKey, cdc *codec.Codec) Keeper

NewKeeper creates new instances of the UTXO Keeper.

func (Keeper) DeleteOutPoint

func (k Keeper) DeleteOutPoint(ctx sdk.Context, outpoint OutPoint)

DeleteOutPoint deletes the given outpoint from the UTXO list.

func (Keeper) GetAccOutput

func (k Keeper) GetAccOutput(ctx sdk.Context, id Hash) AccOutput

GetAccOutput - gets a AccOutput from the store.

func (Keeper) GetTx

func (k Keeper) GetTx(ctx sdk.Context, hash Hash) Tx

GetTx - gets a transaction from the store.

func (Keeper) HasAccOutput

func (k Keeper) HasAccOutput(ctx sdk.Context, id Hash) bool

HasAccOutput - checks if an account output by the given ID exists.

func (Keeper) HasOutPoint

func (k Keeper) HasOutPoint(ctx sdk.Context, outpoint OutPoint) bool

HasOutPoint checks if the given outpoint exists in the UTXO list.

func (Keeper) HasTx

func (k Keeper) HasTx(ctx sdk.Context, hash Hash) bool

HasTx checks if a transaction by the given hash exists.

func (Keeper) ListAccOutput

func (k Keeper) ListAccOutput(ctx sdk.Context) []AccOutput

ListAccOutput - get all account UTXO records.

func (Keeper) ListTx

func (k Keeper) ListTx(ctx sdk.Context) ([]Tx, []Hash)

ListTx - get all account UTXO records.

func (Keeper) ListUtxo

func (k Keeper) ListUtxo(ctx sdk.Context) []OutPoint

ListUtxo - get all account UTXO records.

func (Keeper) PutAccOutput

func (k Keeper) PutAccOutput(ctx sdk.Context, accUtxo AccOutput)

PutAccOutput - saves an account UTXO to the store.

func (Keeper) PutOutPoint

func (k Keeper) PutOutPoint(ctx sdk.Context, outpoint OutPoint)

PutOutPoint saves an outpoint to the UTXO store.

func (Keeper) PutTx

func (k Keeper) PutTx(ctx sdk.Context, hash Hash, tx Tx)

PutTx - saves a transaction to the store.

type MsgBirthAccOutput

type MsgBirthAccOutput struct {
	Amount  sdk.Coin
	Address sdk.AccAddress
}

MsgBirthAccOutput defines a BirthAccOutput message.

func NewMsgBirthAccOutput

func NewMsgBirthAccOutput(amount sdk.Coin, address sdk.AccAddress) MsgBirthAccOutput

NewMsgBirthAccOutput is the constructor function for MsgBirthAccOutput.

func (MsgBirthAccOutput) GetSignBytes

func (msg MsgBirthAccOutput) GetSignBytes() []byte

GetSignBytes Implements Msg.

func (MsgBirthAccOutput) GetSigners

func (msg MsgBirthAccOutput) GetSigners() []sdk.AccAddress

GetSigners Implements Msg.

func (MsgBirthAccOutput) Route

func (msg MsgBirthAccOutput) Route() string

Route Implements Msg.

func (MsgBirthAccOutput) Type

func (msg MsgBirthAccOutput) Type() string

Type Implements Msg.

func (MsgBirthAccOutput) ValidateBasic

func (msg MsgBirthAccOutput) ValidateBasic() sdk.Error

ValidateBasic Implements Msg.

type MsgTx

type MsgTx struct {
	Tx     Tx
	Signer sdk.AccAddress
}

MsgTx represents a UTXO based transaction.

func NewMsgTx

func NewMsgTx(tx Tx, signer sdk.AccAddress) MsgTx

NewMsgTx creates a new transaction message.

func (MsgTx) GetSignBytes

func (msg MsgTx) GetSignBytes() []byte

GetSignBytes Implements Msg.

func (MsgTx) GetSigners

func (msg MsgTx) GetSigners() []sdk.AccAddress

GetSigners Implements Msg.

func (MsgTx) Route

func (msg MsgTx) Route() string

Route Implements Msg.

func (MsgTx) Type

func (msg MsgTx) Type() string

Type Implements Msg.

func (MsgTx) ValidateBasic

func (msg MsgTx) ValidateBasic() sdk.Error

ValidateBasic Implements Msg.

type OutPoint

type OutPoint struct {
	Hash  Hash
	Index int32
}

OutPoint identifies an output from a previous transaction by index. Index >= 0 indicates Hash is a transaction ID. Index = -1 indicates Hash refers to an account based output birth record. Index = -2 indicates Hash refers to a voucher based output birth record.

type OutPointVal

type OutPointVal struct {
	Hash  Hash
	Index int32
	Value uint64
}

OutPointVal is an outpoint and it's value.

type PayToAddress

type PayToAddress struct {
	Address sdk.AccAddress
}

PayToAddress indicates the UTXO is payable to an address.

type Tx

type Tx struct {
	TxIn     []TxIn
	TxOut    []TxOut
	LockTime uint32
}

Tx represents a transaction.

func NewTxPayToAddress

func NewTxPayToAddress(cdc *codec.Codec, sig []byte, hash []byte, index int32, amount uint64, change uint64, from sdk.AccAddress, to sdk.AccAddress) Tx

NewTxPayToAddress creates a transaction payload to pay to an address.

type TxIn

type TxIn struct {
	Input    OutPoint
	Witness  []byte
	Sequence uint32
}

TxIn represents a transaction input.

type TxOut

type TxOut struct {
	Value    uint64
	PkScript []byte
}

TxOut represents a transaction output. PkScript is the go-amino binary marshalled PayTo* struct.

type Wallet

type Wallet struct {
	Balance uint64
	Entries []OutPointVal
}

Wallet represents a balance and UTXOs for an address.

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

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