txo

package
v0.0.0-...-7ee7fde Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2020 License: Apache-2.0 Imports: 7 Imported by: 8

Documentation

Overview

Copyright (c) 2018-2020. The asimov developers Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2018-2020. The asimov developers Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2018-2020. The asimov developers Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	LockEntryLength = common.HashLength + 8
)

Variables

This section is empty.

Functions

func PickVoteArgument

func PickVoteArgument(data []byte) uint32

PickVoteArgument return the vote id from contract data A standard vote tx request data contains at least one param which takes 32 bytes.

Types

type LockEntry

type LockEntry struct {
	Id     VoteId
	Amount int64
}

LockEntry houses details about a lock record in a lock view such as the duration of the block when to be unlock, lock amount, lock id, and which sequence lock.

func (*LockEntry) Clone

func (le *LockEntry) Clone() *LockEntry

func (*LockEntry) Deserialize

func (le *LockEntry) Deserialize(serialized []byte)

func (*LockEntry) Serialize

func (le *LockEntry) Serialize(serialized []byte)

type LockItem

type LockItem struct {
	Entries map[VoteId]*LockEntry
}

func DeserializeLockItem

func DeserializeLockItem(serialized []byte) (*LockItem, error)

DeserializeLockItem decodes a lock item from the passed serialized byte slice into a new UtxoEntry using a format that is suitable for long-term storage. The format is described in detail above.

func NewLockItem

func NewLockItem() *LockItem

func (*LockItem) Bytes

func (li *LockItem) Bytes() []byte

func (*LockItem) Clone

func (li *LockItem) Clone() *LockItem

func (*LockItem) EntriesList

func (li *LockItem) EntriesList() []*LockEntry

func (*LockItem) Merge

func (li *LockItem) Merge(other *LockItem) *LockItem

func (*LockItem) PutEntry

func (li *LockItem) PutEntry(entry *LockEntry)

func (*LockItem) String

func (li *LockItem) String() (res string)

type SpentTxOut

type SpentTxOut struct {
	// Amount is the amount of the output.
	Amount int64

	// PkScipt is the the public key script for the output.
	PkScript []byte

	// Round is the height of the the block containing the creating tx.
	Height int32

	// Denotes if the creating tx is a coinbase.
	IsCoinBase bool

	Asset *protos.Asset
}

SpentTxOut contains a spent transaction output and potentially additional contextual information such as whether or not it was contained in a coinbase transaction, the version of the transaction it was contained in, and which block height the containing transaction was included in. As described in the comments above, the additional contextual information will only be valid when this spent txout is spending the last unspent output of the containing transaction.

type TxMark

type TxMark struct {
	MsgTx  *protos.MsgTx
	Action ViewAction
}

type UtxoEntry

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

UtxoEntry houses details about a transaction output in a utxo view such as whether or not it was contained in a coinbase tx, the height of the block that contains the tx, whether or not it is spent, its public key script, and how much it pays.

func NewUtxoEntry

func NewUtxoEntry(amount int64, pkScript []byte, blockHeight int32, coinbase bool,
	asset *protos.Asset, lockItem *LockItem) *UtxoEntry

func (*UtxoEntry) Amount

func (entry *UtxoEntry) Amount() int64

Amount returns the amount of the output.

func (*UtxoEntry) Asset

func (entry *UtxoEntry) Asset() *protos.Asset

Asset returns the asset for the output.

func (*UtxoEntry) BlockHeight

func (entry *UtxoEntry) BlockHeight() int32

BlockHeight returns the height of the block containing the output.

func (*UtxoEntry) Clone

func (entry *UtxoEntry) Clone() *UtxoEntry

Clone returns a shallow copy of the utxo entry.

func (*UtxoEntry) IsCoinBase

func (entry *UtxoEntry) IsCoinBase() bool

IsCoinBase returns whether or not the output was contained in a coinbase transaction.

func (*UtxoEntry) IsModified

func (entry *UtxoEntry) IsModified() bool

IsModified returns whether or not the output has been modified since it was loaded.

func (*UtxoEntry) IsSpent

func (entry *UtxoEntry) IsSpent() bool

IsSpent returns whether or not the output has been spent based upon the current state of the unspent transaction output view it was obtained from.

func (*UtxoEntry) LockItem

func (entry *UtxoEntry) LockItem() *LockItem

func (*UtxoEntry) PackedFlags

func (entry *UtxoEntry) PackedFlags() uint8

func (*UtxoEntry) PkScript

func (entry *UtxoEntry) PkScript() []byte

PkScript returns the public key script for the output.

func (*UtxoEntry) ResetModified

func (entry *UtxoEntry) ResetModified()

func (*UtxoEntry) SetLockItem

func (entry *UtxoEntry) SetLockItem(lockItem *LockItem)

func (*UtxoEntry) SetPkScript

func (entry *UtxoEntry) SetPkScript(pkscript []byte)

func (*UtxoEntry) Spend

func (entry *UtxoEntry) Spend()

Spend marks the output as spent. Spending an output that is already spent has no effect.

func (*UtxoEntry) UnSpent

func (entry *UtxoEntry) UnSpent()

UnSpent marks the output as unspent.

func (*UtxoEntry) Update

func (entry *UtxoEntry) Update(amount int64, pkScript []byte, blockHeight int32, coinbase bool,
	asset *protos.Asset, lockItem *LockItem)

type UtxoMap

type UtxoMap map[protos.OutPoint]*UtxoEntry

type UtxoViewpoint

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

UtxoViewpoint represents a view into the set of unspent transaction outputs from a specific point of view in the chain. For example, it could be for the end of the main chain, some point in the history of the main chain, or down a side chain.

The unspent outputs are needed by other transactions for things such as script validation and double spend prevention.

func NewUtxoViewpoint

func NewUtxoViewpoint() *UtxoViewpoint

NewUtxoViewpoint returns a new empty unspent transaction output view.

func (*UtxoViewpoint) AddEntry

func (view *UtxoViewpoint) AddEntry(outpoint protos.OutPoint, entry *UtxoEntry)

AddEntry update entries via outpoint and entry.

func (*UtxoViewpoint) AddTxOut

func (view *UtxoViewpoint) AddTxOut(outpoint protos.OutPoint, txOut *protos.TxOut,
	isCoinBase bool, blockHeight int32, lockitem *LockItem)

addTxOut adds the specified output to the view if it is not provably unspendable. When the view already has an entry for the output, it will be marked unspent. All fields will be updated for existing entries since it's possible it has changed during a reorg.

func (*UtxoViewpoint) AddTxOuts

func (view *UtxoViewpoint) AddTxOuts(hash *common.Hash, tx *protos.MsgTx,
	isCoinBase bool, blockHeight int32) map[protos.Asset]*LockItem

AddTxOuts adds all outputs in the passed transaction which are not provably unspendable to the view. When the view already has entries for any of the outputs, they are simply marked unspent. All fields will be updated for existing entries since it's possible it has changed during a reorg.

func (*UtxoViewpoint) AddViewSign

func (view *UtxoViewpoint) AddViewSign(sig *protos.MsgBlockSign)

AddViewSign updates the view by adding block sign by the passed transaction.

func (*UtxoViewpoint) AddViewTx

func (view *UtxoViewpoint) AddViewTx(hash *common.Hash, tx *protos.MsgTx)

AddViewTx updates the view by adding txs by the passed transaction.

func (*UtxoViewpoint) BestHash

func (view *UtxoViewpoint) BestHash() *common.Hash

BestHash returns the hash of the best block in the chain the view currently respresents.

func (*UtxoViewpoint) Commit

func (view *UtxoViewpoint) Commit()

Commit prunes all entries marked modified that are now fully spent and marks all entries as unmodified.

func (*UtxoViewpoint) ConstructLockItems

func (view *UtxoViewpoint) ConstructLockItems(tx *protos.MsgTx, nextHeight int32) ([]*LockItem, map[protos.Asset]*LockItem)

Outputs' lock items are inherited from inputs lock items. The rule is very simple: Order First. In the case that some asset's outputs amount is less than lock item amount, fee inherit the remain lock item. Note: 1. Each lock item for asset is independent. 2. Any lock item is not allowed exceed than input or output's amount.

Idx |       Input        |         Output     |   fee
    | Amount | lock item | Amount | lock item | Amount | lock item |

eg 1.

0  | 10000  |  10000    | 10000  |    10000  |

eg 2.

0  | 10000  |  10000    | 30000  |    15000  |
1  | 20000  |  5000     |

eg 3.

0  | 10000  |  10000    | 12000  |    12000  |
1  | 20000  |  5000     | 18000  |    3000   |

eg 4.

0  | 10000  |  10000    | 2000   |    2000   | 1000   |    1000   |
1  |                    | 7000   |    7000   |

func (*UtxoViewpoint) Entries

func (view *UtxoViewpoint) Entries() map[protos.OutPoint]*UtxoEntry

Entries returns the underlying map that stores of all the utxo entries.

func (*UtxoViewpoint) Exist

func (view *UtxoViewpoint) Exist(outpoint protos.OutPoint) bool

Exist returns true if the passed output exists in the view otherwise false.

func (*UtxoViewpoint) LookupEntry

func (view *UtxoViewpoint) LookupEntry(outpoint protos.OutPoint) *UtxoEntry

LookupEntry returns information about a given transaction output according to the current state of the view. It will return nil if the passed output does not exist in the view or is otherwise not available such as when it has been disconnected during a reorg.

func (*UtxoViewpoint) RemoveEntry

func (view *UtxoViewpoint) RemoveEntry(outpoint protos.OutPoint)

RemoveEntry removes the given transaction output from the current state of the view. It will have no effect if the passed output does not exist in the view.

func (*UtxoViewpoint) RemoveViewSign

func (view *UtxoViewpoint) RemoveViewSign(sig *protos.MsgBlockSign)

mark sign as ViewRm.

func (*UtxoViewpoint) RemoveViewTx

func (view *UtxoViewpoint) RemoveViewTx(hash *common.Hash)

RemoveViewTx mark the passed transaction as ViewRm.

func (*UtxoViewpoint) SetBestHash

func (view *UtxoViewpoint) SetBestHash(hash *common.Hash)

SetBestHash sets the hash of the best block in the chain the view currently respresents.

func (*UtxoViewpoint) TryGetSignAction

func (view *UtxoViewpoint) TryGetSignAction(sign *protos.MsgBlockSign) ViewAction

TryGetSignAction returns action about a given block sign according to the current state of the view. It will return ViewUnknown if the passed block sign does not exist in the view.

func (*UtxoViewpoint) Txs

func (view *UtxoViewpoint) Txs() map[common.Hash]TxMark

Txs returns the underlying map that stores of all the txs.

type ViewAction

type ViewAction int
const (
	// solidity compiler pick four bytes for method mark.
	ContractMethodLength = 4

	ViewUnknown ViewAction = 0
	ViewAdd     ViewAction = 1
	ViewRm      ViewAction = 2
)

type VoteId

type VoteId [common.HashLength]byte

func NewVoteId

func NewVoteId(addr common.Address, id uint32) *VoteId

Jump to

Keyboard shortcuts

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