utxoutil

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: Apache-2.0, BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package utxoutil is used to build value transaction

Package utxoutil contains number of utility functions useful while manipulating outputs and constructing transactions. The ConsumableOutput is a wrapper of an ledgerstate.Output which allows 'consuming' tokens and tracking remaining balances. The Builder is a flexible tansaction builder tool. It use ConsumableOutput -s to build arbitrary transactions along 'consume->spend' scheme.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConsumableBalance

func ConsumableBalance(color ledgerstate.Color, consumables ...*ConsumableOutput) uint64

ConsumableBalance returns how many tokens of the given color can be consumed from remaining

func ConsumeColored

func ConsumeColored(color ledgerstate.Color, amount uint64, consumables ...*ConsumableOutput) bool

ConsumeColored specified amount of colored tokens sequentially from specified ConsumableOutputs return nil if it was a success. In case of failure ConsumableOutputs remaining unchanged

func ConsumeMany

func ConsumeMany(amounts map[ledgerstate.Color]uint64, consumables ...*ConsumableOutput) bool

ConsumeMany consumes whole collection of colored balances

func ConsumeRemaining

func ConsumeRemaining(consumables ...*ConsumableOutput) map[ledgerstate.Color]uint64

ConsumeRemaining consumes all remaining tokens and return map of wasConsumed balances

func EnoughBalance

func EnoughBalance(color ledgerstate.Color, amount uint64, consumables ...*ConsumableOutput) bool

EnoughBalance checks if it is enough tokens of the given color remains in the consumables

func EnoughBalances

func EnoughBalances(amounts map[ledgerstate.Color]uint64, consumables ...*ConsumableOutput) bool

EnoughBalances checks is it is enough remaining tokens to consume whole collection of balances

func FindAliasConsumableInput

func FindAliasConsumableInput(aliasAddr ledgerstate.Address, consumables ...*ConsumableOutput) (*ledgerstate.AliasOutput, int, bool)

FindAliasConsumableInput finds chain output with given alias address

func GetMintedAmounts

func GetMintedAmounts(tx *ledgerstate.Transaction) map[ledgerstate.Color]uint64

GetMintedAmounts analyzes outputs and extracts information of new colors which were minted and respective amounts of tokens

func GetSingleChainedAliasOutput

func GetSingleChainedAliasOutput(tx *ledgerstate.Transaction) (*ledgerstate.AliasOutput, error)

GetSingleChainedAliasOutput expects exactly one chained output in the transaction and returns it returns: - nil and no error if found none - error if there's more than 1

func GetSingleSender

func GetSingleSender(tx *ledgerstate.Transaction) (ledgerstate.Address, error)

GetSingleSender analyzes transaction and signatures and retrieves single address which is consistent to be a 'sender': if it do not have alias input, the address corresponding to the only signature is returned if it has a single alias input (i.e. output is not an origin) it returns a alias address of the chain

func MakeUTXOInputs

func MakeUTXOInputs(consumables ...*ConsumableOutput) (ledgerstate.Inputs, []ledgerstate.Output)

MakeUTXOInputs from the list of consumables makes sorted inputs with NewInputs() and returns corresponding outputs in the same (changed) order

func MustConsumeColored

func MustConsumeColored(color ledgerstate.Color, amount uint64, consumables ...*ConsumableOutput)

MustConsumeColored same as as ConsumeColor only panics on unsuccessful consume

func ToOutputs

func ToOutputs(consumables ...*ConsumableOutput) []ledgerstate.Output

ToOutputs extracts output objects from consumables into the slice

func UnlockInputsWithED25519KeyPairs

func UnlockInputsWithED25519KeyPairs(inputs []ledgerstate.Output, essence *ledgerstate.TransactionEssence, keyPairs ...*ed25519.KeyPair) ([]ledgerstate.UnlockBlock, error)

UnlockInputsWithED25519KeyPairs signs the transaction essence with provided ED25519 pair. Then it unlocks inputs provided as a list of outputs using those signatures and returns a list of unlock blocks in the same order as inputs. It only uses no more signatures as it is needed to unlock all inputs. Other unlock blocks are references The function unlocks the following output types: - ledgerstate.AliasOutput - ledgerstate.ExtendedLockedOutput - ledgerstate.SigLockedSingleOutput - ledgerstate.SigLockedColoredOutput It unlocks inputs by using the following unlock block types: - ledgerstate.SignatureUnlockBlock - ledgerstate.ReferenceUnlockBlock - ledgerstate.AliasUnlockBlock

Types

type Builder

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

Builder builder implements a structure and interface to build transactions Initial input is a list of outputs which can be used as consumable inputs Balances are tracked by "consuming" tokens from inputs and then "spending" them to outputs "consuming" tokens from inputs means:

  • tracking "remaining" part of tokens in each consumable output
  • placing consumed token into the "consumedUnspent"
  • By SpendConsumedUnspent all tokens are cleared from "consumedUnspent" and can be used as a token payload to the output

func NewBuilder

func NewBuilder(inputs ...ledgerstate.Output) *Builder

NewBuilder creates new builder for outputs

func (*Builder) AddAliasOutputAsRemainder

func (b *Builder) AddAliasOutputAsRemainder(addressAlias ledgerstate.Address, stateData []byte, compress ...bool) error

AddAliasOutputAsRemainder forms an reminder by creating new alias output

func (*Builder) AddExtendedOutputConsume

func (b *Builder) AddExtendedOutputConsume(targetAddress ledgerstate.Address, data []byte, amounts map[ledgerstate.Color]uint64, mint ...uint64) error

AddExtendedOutputConsume add new output. Ensures enough unspent funds by consuming if necessary

func (*Builder) AddExtendedOutputSpend

func (b *Builder) AddExtendedOutputSpend(targetAddress ledgerstate.Address, data []byte, amounts map[ledgerstate.Color]uint64, mint ...uint64) error

AddExtendedOutputSpend adds extended output using unspent amounts and spends it. Fails of not enough. Do not consume inputs

func (*Builder) AddMintingOutputConsume

func (b *Builder) AddMintingOutputConsume(targetAddress ledgerstate.Address, amount uint64, payload ...[]byte) error

AddMintingOutputConsume mints new tokens. Consumes additional iotas if needed

func (*Builder) AddNewAliasMint

func (b *Builder) AddNewAliasMint(balances map[ledgerstate.Color]uint64, stateAddress ledgerstate.Address, stateData []byte) error

AddNewAliasMint creates new self governed chain. The identity of the chain is not known until the full transaction is produced

func (*Builder) AddOutputAndSpendUnspent

func (b *Builder) AddOutputAndSpendUnspent(out ledgerstate.Output) error

AddOutputAndSpendUnspent spends the consumed-unspent tokens and adds output

func (*Builder) AddRemainderOutputIfNeeded

func (b *Builder) AddRemainderOutputIfNeeded(remainderAddr ledgerstate.Address, data []byte, compress ...bool) error

AddRemainderOutputIfNeeded consumes already touched inputs and spends consumed-unspend. Creates reminder output if needed

func (*Builder) AddSigLockedColoredOutput

func (b *Builder) AddSigLockedColoredOutput(targetAddress ledgerstate.Address, amounts map[ledgerstate.Color]uint64, mint ...uint64) error

AddSigLockedColoredOutput creates output, consumes inputs if needed

func (*Builder) AddSigLockedIOTAOutput

func (b *Builder) AddSigLockedIOTAOutput(targetAddress ledgerstate.Address, amount uint64, mint ...uint64) error

AddSigLockedIOTAOutput adds output with iotas by consuming inputs supports minting (coloring) of part of consumed iotas

func (*Builder) AliasNextChainedOutput

func (b *Builder) AliasNextChainedOutput(addressAlias ledgerstate.Address) (*ledgerstate.AliasOutput, error)

AliasNextChainedOutput creates chained output without consuming it

func (*Builder) BuildEssence

func (b *Builder) BuildEssence(compress ...bool) (*ledgerstate.TransactionEssence, []ledgerstate.Output, error)

BuildEssence builds essence of the transaction. Compress option: - true means take all consumable inputs - false means take only touched (consumed) outputs. This is the default

func (*Builder) BuildWithED25519

func (b *Builder) BuildWithED25519(keyPairs ...*ed25519.KeyPair) (*ledgerstate.Transaction, error)

BuildWithED25519 build complete transaction and signs/unlocks with provided keys

func (*Builder) Clone

func (b *Builder) Clone() *Builder

Clone creates deep copy of the builder

func (*Builder) ConsumeAliasInput

func (b *Builder) ConsumeAliasInput(addressAlias ledgerstate.Address) error

ConsumeAliasInput consumes chain input by alias

func (*Builder) ConsumeAmounts

func (b *Builder) ConsumeAmounts(amounts map[ledgerstate.Color]uint64) bool

ConsumeAmounts consumes specified amounts and adds it to consumed-unspent pool

func (*Builder) ConsumeInputByOutputID

func (b *Builder) ConsumeInputByOutputID(id ledgerstate.OutputID) error

ConsumeInputByOutputID consumes input by outputID

func (*Builder) ConsumeRemainingBalances

func (b *Builder) ConsumeRemainingBalances(compress bool) []*ConsumableOutput

ConsumeRemainingBalances consumes touched balances

func (*Builder) ConsumedUnspent

func (b *Builder) ConsumedUnspent() map[ledgerstate.Color]uint64

ConsumedUnspent return consumed-unspend pool

func (*Builder) Spend

func (b *Builder) Spend(spend map[ledgerstate.Color]uint64) error

Spend spends from consumed-unspend. Return an error if not enough funds

func (*Builder) SpendConsumedUnspent

func (b *Builder) SpendConsumedUnspent() map[ledgerstate.Color]uint64

SpendConsumedUnspent spends all consumed-unspent pool (empties it) and returns what was spent

func (*Builder) WithAccessPledge

func (b *Builder) WithAccessPledge(id identity.ID) *Builder

WithAccessPledge sets the access mana pledge

func (*Builder) WithConsensusPledge

func (b *Builder) WithConsensusPledge(id identity.ID) *Builder

WithConsensusPledge sets the consensus mana pledge

func (*Builder) WithTimestamp

func (b *Builder) WithTimestamp(t time.Time) *Builder

WithTimestamp sets timestamp

func (*Builder) WithVersion

WithVersion sets Version property

type ConsumableOutput

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

ConsumableOutput represents a wrapper of the output object. It allows 'consume' tokens and track how many remain to be consumed

func NewConsumables

func NewConsumables(out ...ledgerstate.Output) []*ConsumableOutput

NewConsumables creates a slice of consumables out of slice of output objects

func SelectConsumed

func SelectConsumed(consumables ...*ConsumableOutput) []*ConsumableOutput

SelectConsumed filters out untouched consumables and returns those which were consumed

func (*ConsumableOutput) Clone

func (o *ConsumableOutput) Clone() *ConsumableOutput

Clone clones the consumable

func (*ConsumableOutput) ConsumableBalance

func (o *ConsumableOutput) ConsumableBalance(color ledgerstate.Color) uint64

ConsumableBalance return number of tokens remaining to consume on the consumable

func (*ConsumableOutput) NothingRemains

func (o *ConsumableOutput) NothingRemains() bool

NothingRemains returns true if no tokens remain to be consumed

func (*ConsumableOutput) WasConsumed

func (o *ConsumableOutput) WasConsumed() bool

WasConsumed return true if consumable was 'touched', it some tokens were already consumed

Jump to

Keyboard shortcuts

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