asiutil

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: 31 Imported by: 0

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 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 Use of this source code is governed by an ISC license that can be found in the LICENSE file.

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 Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	//unknown,
	TxTypeUnknown int = 0

	//unsupported type, illegal tx type.
	TxTypeUnsupport int = 1

	// generated by vm, it happens when transferring coin in contract executions.
	TxTypeVM int = 2

	//standard tx that generated by wallet.
	TxTypeNormal int = 4
)
View Source
const TransferCreationIdx = math.MaxUint32 - 1
View Source
const TransferMintIdx = math.MaxUint32 - 2
View Source
const TxIndexUnknown = -1

TxIndexUnknown is the value returned for a transaction index that is unknown. This is typically because the transaction has not been inserted into a block yet.

Variables

View Source
var AsimovAsset = protos.Asset{}

Asimov coin asset

Functions

func AppDataDir

func AppDataDir(appName string, roaming bool) string

AppDataDir returns an operating system specific directory to be used for storing application data for an application.

The appName parameter is the name of the application the data directory is being requested for. This function will prepend a period to the appName for POSIX style operating systems since that is standard practice. An empty appName or one with a single dot is treated as requesting the current directory so only "." will be returned. Further, the first character of appName will be made lowercase for POSIX style operating systems and uppercase for Mac and Windows since that is standard practice.

The roaming parameter only applies to Windows where it specifies the roaming application data profile (%APPDATA%) should be used instead of the local one (%LOCALAPPDATA%) that is used by default.

Example results:

dir := AppDataDir("myapp", false)
 POSIX (Linux/BSD): ~/.myapp
 Mac OS: $HOME/Library/Application Support/Myapp
 Windows: %LOCALAPPDATA%\Myapp
 Plan 9: $home/myapp

func DecodeAddress

func DecodeAddress(addr string) (common.IAddress, error)

DecodeAddress decodes the string encoding of an address and returns the Address if addr is a valid encoding for a known address type.

The bitcoin network the address is associated with is extracted if possible. When the address does not encode the network, such as in the case of a raw public key, the address will be associated with the passed defaultNet.

func GenInputHash

func GenInputHash(msgTx *protos.MsgTx) []byte

GenInputHash generates hash from txIn.PreviousOutPoint.Hash and txIn.PreviousOutPoint.Index

func GetBlockPair

func GetBlockPair(db database.Transactor, hash *common.Hash) (block *Block, vblock *VBlock, err error)

GetBlockPair returns a new instance of an asimov block

func HomeDir

func HomeDir() string

func IsMintOrCreateInput

func IsMintOrCreateInput(in *protos.TxIn) bool

IsMintOrCreateInput returns operate type of input, mint or create

func LoadBlockFromFile

func LoadBlockFromFile(file string) (*protos.MsgBlock, error)

LoadBlockFromFile decodes a block from r into the receiver using a format that is suitable for long-term storage such as a database while respecting the Version field in the block

func NewTLSCertPair

func NewTLSCertPair(organization string, validUntil time.Time, extraHosts []string) (cert, key []byte, err error)

NewTLSCertPair returns a new PEM-encoded x.509 certificate pair based on a 521-bit ECDSA private key. The machine's local interface addresses and all variants of IPv4 and IPv6 localhost are included as valid IP addresses.

Types

type AssetsList

type AssetsList []protos.Asset

assetList defines o list of asset

func (AssetsList) Len

func (al AssetsList) Len() int

func (AssetsList) Less

func (al AssetsList) Less(i, j int) bool

func (AssetsList) Swap

func (al AssetsList) Swap(i, j int)

type Block

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

Block defines a bitcoin block that provides easier and more efficient manipulation of raw blocks. It also memoizes hashes for the block and its transactions on their first access so subsequent accesses don't have to repeat the relatively expensive hashing operations.

func NewBlock

func NewBlock(msgBlock *protos.MsgBlock) *Block

NewBlock returns a new instance of an asimov block given an underlying protos.MsgBlock. See Block.

func NewBlockFromBlockAndBytes

func NewBlockFromBlockAndBytes(msgBlock *protos.MsgBlock, serializedBlock []byte) *Block

NewBlockFromBlockAndBytes returns a new instance of a flow block given an underlying protos.MsgBlock and the serialized bytes for it. See Block.

func NewBlockFromBytes

func NewBlockFromBytes(serializedBlock []byte) (*Block, error)

NewBlockFromBytes returns a new instance of a flow block given the serialized bytes. See Block.

func (*Block) Bytes

func (b *Block) Bytes() ([]byte, error)

Bytes returns the serialized bytes for the Block. This is equivalent to calling Serialize on the underlying protos.MsgBlock, however it caches the result so subsequent calls are more efficient.

func (*Block) GetBalance

func (b *Block) GetBalance(address common.Address) *txo.UtxoMap

GetBalance returns balance of target address

func (*Block) Hash

func (b *Block) Hash() *common.Hash

Hash returns the block identifier hash for the Block. This is equivalent to calling BlockHash on the underlying protos.MsgBlock, however it caches the result so subsequent calls are more efficient.

func (*Block) Height

func (b *Block) Height() int32

Round returns the saved height of the block in the block chain. This value will be BlockHeightUnknown if it hasn't already explicitly been set.

func (*Block) IsSigned

func (b *Block) IsSigned() bool

func (*Block) MsgBlock

func (b *Block) MsgBlock() *protos.MsgBlock

MsgBlock returns the underlying protos.MsgBlock for the Block.

func (*Block) PutBalance

func (b *Block) PutBalance(address common.Address, balance *txo.UtxoMap)

PutBalance puts utxo of target address into cache

func (*Block) Round

func (b *Block) Round() uint32

Round returns the number of round of the block

func (*Block) SetHeight

func (b *Block) SetHeight(height int32)

SetHeight sets the height of the block in the block chain.

func (*Block) Signs

func (b *Block) Signs() []*BlockSign

Signs returns signatures from block

func (*Block) Transactions

func (b *Block) Transactions() []*Tx

Transactions returns a slice of wrapped transactions (vvsutil.Tx) for all transactions in the Block. This is nearly equivalent to accessing the raw transactions (protos.MsgTx) in the underlying protos.MsgBlock, however it instead provides easy access to wrapped versions (vvsutil.Tx) of them.

func (*Block) Tx

func (b *Block) Tx(txNum int) (*Tx, error)

Tx returns a wrapped transaction (vvsutil.Tx) for the transaction at the specified index in the Block. The supplied index is 0 based. That is to say, the first transaction in the block is txNum 0. This is nearly equivalent to accessing the raw transaction (protos.MsgTx) from the underlying protos.MsgBlock, however the wrapped transaction has some helpful properties such as caching the hash so subsequent calls are more efficient.

func (*Block) TxHash

func (b *Block) TxHash(txNum int) (*common.Hash, error)

TxHash returns the hash for the requested transaction number in the Block. The supplied index is 0 based. That is to say, the first transaction in the block is txNum 0. This is equivalent to calling TxHash on the underlying protos.MsgTx, however it caches the result so subsequent calls are more efficient.

func (*Block) TxLoc

func (b *Block) TxLoc() ([]protos.TxLoc, error)

TxLoc returns the offsets and lengths of each transaction in a raw block. It is used to allow fast indexing into transactions within the raw byte stream.

type BlockSign

type BlockSign struct {
	MsgSign *protos.MsgBlockSign
	// contains filtered or unexported fields
}

BlockSign stores the signature hashes of msgBlock

func NewBlockSign

func NewBlockSign(msgTx *protos.MsgBlockSign) *BlockSign

NewBlockSign sets MsgBlockSign into BlockSign

func (*BlockSign) Hash

func (t *BlockSign) Hash() *common.Hash

Hash returns hash in the blockSign. if not found, generate new one

type MissVBlockError

type MissVBlockError string

MissVBlockError describes an error due to accessing an element that is out of range.

func (MissVBlockError) Error

func (e MissVBlockError) Error() string

Error satisfies the error interface and prints human-readable errors.

type OutOfRangeError

type OutOfRangeError string

OutOfRangeError describes an error due to accessing an element that is out of range.

func (OutOfRangeError) Error

func (e OutOfRangeError) Error() string

Error satisfies the error interface and prints human-readable errors.

type Tx

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

Tx defines a bitcoin transaction that provides easier and more efficient manipulation of raw transactions. It also memorizes the hash for the transaction on its first access so subsequent accesses don't have to repeat the relatively expensive hashing operations.

func MergeTxVtx

func MergeTxVtx(txs []*Tx, vtxs []*Tx) []*Tx

merge normal tx and virtual tx into a single list, to match the order of stxo set. the virtual tx will follow the parent normal tx(that tx contains contract execution and generates virtual tx) for ex: tx1, tx2, tx3, tx4 vtx2,vtx2-2, vtx3 ---> tx1, tx2, vtx2, vtx2-2, tx3, vtx3, tx4

func NewTx

func NewTx(msgTx *protos.MsgTx) *Tx

NewTx returns a new instance of a bitcoin transaction given an underlying protos.MsgTx. See Tx.

func NewTxFromBytes

func NewTxFromBytes(serializedTx []byte) (*Tx, error)

NewTxFromBytes returns a new instance of a bitcoin transaction given the serialized bytes. See Tx.

func NewTxFromReader

func NewTxFromReader(r io.Reader) (*Tx, error)

NewTxFromReader returns a new instance of a bitcoin transaction given a Reader to deserialize the transaction. See Tx.

func (*Tx) GetInputHash

func (t *Tx) GetInputHash() []byte

GetInputHash returns hash of input from transaction

func (*Tx) Hash

func (t *Tx) Hash() *common.Hash

Hash returns the hash of the transaction. This is equivalent to calling TxHash on the underlying protos.MsgTx, however it caches the result so subsequent calls are more efficient.

func (*Tx) Index

func (t *Tx) Index() int

Index returns the saved index of the transaction within a block. This value will be TxIndexUnknown if it hasn't already explicitly been set.

func (*Tx) MsgTx

func (t *Tx) MsgTx() *protos.MsgTx

MsgTx returns the underlying protos.MsgTx for the transaction.

func (*Tx) SetIndex

func (t *Tx) SetIndex(index int)

SetIndex sets the index of the transaction in within a block.

func (*Tx) Type

func (t *Tx) Type() int

type VBlock

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

VBlock defines an asimov virtual block that provides easier and more efficient manipulation of raw virtual blocks. It also memorizes hashes for the virtual block and its virtual transactions on their first access so subsequent accesses don't have to repeat the relatively expensive hashing operations.

func NewVBlock

func NewVBlock(msgvBlock *protos.MsgVBlock, blockHash *common.Hash) *VBlock

NewVBlock returns a new instance of an asimov block given an underlying protos.MsgVBlock. See VBlock.

func NewVBlockFromBytes

func NewVBlockFromBytes(serializedBytes []byte, blockHash *common.Hash) (*VBlock, error)

NewVBlockFromBytes returns a new instance of an asimov block given the serialized bytes. See VBlock.

func (*VBlock) Bytes

func (b *VBlock) Bytes() ([]byte, error)

Bytes returns the serialized bytes for the Block. This is equivalent to calling Serialize on the underlying protos.MsgBlock, however it caches the result so subsequent calls are more efficient.

func (*VBlock) Hash

func (b *VBlock) Hash() *common.Hash

Hash returns the block identifier hash for the Block. This is equivalent to calling BlockHash on the underlying protos.MsgBlock, however it caches the result so subsequent calls are more efficient.

func (*VBlock) MsgVBlock

func (b *VBlock) MsgVBlock() *protos.MsgVBlock

MsgBlock returns the underlying protos.MsgBlock for the Block.

func (*VBlock) Transactions

func (b *VBlock) Transactions() []*Tx

Transactions returns a slice of wrapped transactions (vvsutil.Tx) for all transactions in the Block. This is nearly equivalent to accessing the raw transactions (protos.MsgTx) in the underlying protos.MsgBlock, however it instead provides easy access to wrapped versions (vvsutil.Tx) of them.

func (*VBlock) Tx

func (b *VBlock) Tx(txNum int) (*Tx, error)

Tx returns a wrapped transaction (vvsutil.Tx) for the transaction at the specified index in the Block. The supplied index is 0 based. That is to say, the first transaction in the block is txNum 0. This is nearly equivalent to accessing the raw transaction (protos.MsgTx) from the underlying protos.MsgBlock, however the wrapped transaction has some helpful properties such as caching the hash so subsequent calls are more efficient.

func (*VBlock) TxHash

func (b *VBlock) TxHash(txNum int) (*common.Hash, error)

TxHash returns the hash for the requested transaction number in the Block. The supplied index is 0 based. That is to say, the first transaction in the block is txNum 0. This is equivalent to calling TxHash on the underlying protos.MsgTx, however it caches the result so subsequent calls are more efficient.

func (*VBlock) TxLoc

func (b *VBlock) TxLoc() ([]protos.TxLoc, error)

TxLoc returns the offsets and lengths of each transaction in a raw block. It is used to allow fast indexing into transactions within the raw byte stream.

Directories

Path Synopsis
gcs

Jump to

Keyboard shortcuts

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