common

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: 18 Imported by: 48

Documentation

Overview

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.

Package common contains various helper functions.

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.

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 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 (
	//consensus type
	SOLO = iota
	POA
	SATOSHIPLUS
	ConsensusCount
)
View Source
const (
	// XingPerAsimov is the number of xing in one asimov coin (1 ASC).
	XingPerAsimov int64 = 1e8

	// MaxXing is the maximum transaction amount allowed in xing.
	// 10 billion
	MaxXing = 1e10 * XingPerAsimov

	// MaxPrice is the maximum gas price limit.
	MaxPrice = 1000

	// Considering that evm costs 21000 gas, we suppose the average transaction's
	// length is 1k bytes, hence each byte cost 21 gas.
	GasPerByte = 21

	// CoinbaseTxGas use 100000, constantly.
	CoinbaseTxGas = 100000

	// CommandSize is the fixed size of all commands in the common bitcoin message
	// header.  Shorter commands must be zero padded.
	CommandSize = 12

	// MaxBlockSize is the maximum number of bytes within a block
	MaxBlockSize = 2 * 1024 * 1024

	// CoreTeamPercent is the percent of block reward
	CoreTeamPercent = 0.2

	// The gas is used when consensus invoke some readonly function in contract.
	ReadOnlyGas = 2300

	// The gas is used when checking whether an address is in whitelist on limit assets.
	SupportCheckGas = 6000

	// The gas is used when consensus invoke some readonly function in system contract.
	SystemContractReadOnlyGas = 30000000

	// max block height depth which can be included in header.
	// such as block N can include block sign of N-1, ... N-BlockSignDepth
	BlockSignDepth = 10

	// Target gas floor for mined blocks.
	GasFloor = 160000000

	// Target gas ceiling for mined blocks.
	GasCeil = 160000000

	// Min interval time seconds of blocks
	MinBlockInterval = 3

	// Max interval time seconds of blocks
	MaxBlockInterval = 15

	// The default interval time seconds of blocks
	DefaultBlockInterval = 5

	// LockTimeThreshold is the number below which a lock time is
	// interpreted to be a block number.  Since an average of one block
	// is generated per 5 seconds, this allows blocks for about 237
	// years.
	LockTimeThreshold = 1.5e8 // Tue Jul 14 02:40:00 2017 UTC
)
View Source
const (
	// A standard template contract must contains
	// two functions, getTemplateInfo and initTemplate
	// Following two fields are name for these functions.
	GetTemplateInfoFunc = "getTemplateInfo"

	InitTemplateFunc = "initTemplate"

	// empty value of an address type, formatted with string
	EmptyAddressValue = "0x000000000000000000000000000000000000000000"

	// This is the standard template's abi.
	TemplateABI = "" /* 507-byte string literal not displayed */
)
View Source
const (
	// HashLength is the expected length of the hash
	HashLength = 32
	// AddressLength is the expected length of the address
	AddressLength = 21
	// AssetLength is the expected length of the assets
	AssetLength = 12
	// AmountSize is the expected size of amount
	AmountSize = 8

	// MaxHashStringSize is the maximum length of a Hash hash string.
	MaxHashStringSize = HashLength * 2
)

Lengths of hashes and addresses in bytes.

View Source
const (
	// ProtocolVersion is the latest protocol version this package supports.
	ProtocolVersion uint32 = 1

	MinRequestVersion uint32 = 1
	MaxRequestVersion uint32 = 1
)

XXX pedro: we will probably need to bump this.

Variables

View Source
var (
	Big1         = big.NewInt(1)
	Big2         = big.NewInt(2)
	Big0         = big.NewInt(0)
	Big32        = big.NewInt(32)
	Big256       = big.NewInt(256)
	Big257       = big.NewInt(257)
	BigMaxuint32 = big.NewInt(math.MaxUint32)
	BigMaxint64  = big.NewInt(math.MaxInt64)
	BigMaxxing   = big.NewInt(MaxXing)
)

Common big integers often used

View Source
var (
	ConsensusPOA         = HexToAddress("0x63000000000000000000000000000000000000006c")
	ConsensusSatoshiPlus = HexToAddress("0x63000000000000000000000000000000000000006a")
	GenesisOrganization  = HexToAddress("0x630000000000000000000000000000000000000064")
	RegistryCenter       = HexToAddress("0x630000000000000000000000000000000000000065")
	TemplateWarehouse    = HexToAddress("0x630000000000000000000000000000000000000067")
	ValidatorCommittee   = HexToAddress("0x63000000000000000000000000000000000000006b")
)
View Source
var (
	// callCode for `getTemplateInfo` function.
	GetTemplateInfoCallCode = Hex2Bytes("2fb97c1d")

	// callCode for `canTransfer` function of organization
	CanTransferFuncByte = Hex2Bytes("fc588476")

	// callCode for `isRestrictedAsset` function.
	IsRestrictedAssetByte = Hex2Bytes("f0d94a13")

	// callCode for `getOrganizationAddressById` function.
	GetOrganizationAddressByIdByte = Hex2Bytes("c0bb5900")

	// callCode for `getApprovedTemplatesCount` function.
	GetApprovedTemplatesCountByte = Hex2Bytes("ff2e9b4d")

	// callCode for `getSubmittedTemplatesCount` function.
	GetSubmittedTemplatesCountByte = Hex2Bytes("2c47086a")

	// callCode for `getApprovedTemplate` function.
	GetApprovedTemplateByte = Hex2Bytes("214b38d9")

	// callCode for `getSubmittedTemplate` function.
	GetSubmittedTemplateByte = Hex2Bytes("c17168bc")

	// callCode for `getTemplate` function.
	GetTemplateByte = Hex2Bytes("e9e89524")
)
View Source
var (
	PubKeyHashAddrID   byte = 'f' // First byte of a P2PKH address
	ScriptHashAddrID   byte = 's' // First byte of a P2SH address
	ContractHashAddrID byte = 'c' // First byte of a contract address
	PrivateKeyID       byte = 'k' // First byte of a WIF private key
)
View Source
var ContractCodeStrings = map[Address]string{
	ConsensusPOA:         "ConsensusPOA",
	ConsensusSatoshiPlus: "ConsensusSatoshiPlus",
	GenesisOrganization:  "GenesisOrganization",
	RegistryCenter:       "RegistryCenter",
	TemplateWarehouse:    "TemplateWarehouse",
	ValidatorCommittee:   "ValidatorCommittee",
}

Map of ContractCode values back to their constant names for pretty printing.

View Source
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)

ErrHashStrSize describes an error that indicates the caller specified a hash string that has too many characters.

View Source
var (
	// ErrUnknownAddressType describes an error where an address can not
	// decoded as a specific address type due to the string encoding
	// begining with an identifier byte unknown to any standard or
	// registered (via chaincfg.Register) network.
	ErrUnknownAddressType = errors.New("unknown address type")
)

Functions

func Bytes2Hex

func Bytes2Hex(d []byte) string

Bytes2Hex returns the hexadecimal encoding of d.

func ContractConsensusPOA_BatchAddAdminsFunction

func ContractConsensusPOA_BatchAddAdminsFunction() string

func ContractConsensusPOA_BatchAddValidatorsFunction

func ContractConsensusPOA_BatchAddValidatorsFunction() string

func ContractConsensusPOA_BatchRemoveAdminsFunction

func ContractConsensusPOA_BatchRemoveAdminsFunction() string

func ContractConsensusPOA_BatchRemoveValidatorsFunction

func ContractConsensusPOA_BatchRemoveValidatorsFunction() string

func ContractConsensusPOA_CanPerformFunction

func ContractConsensusPOA_CanPerformFunction() string

func ContractConsensusPOA_ConfigureAddressRoleFunction

func ContractConsensusPOA_ConfigureAddressRoleFunction() string

func ContractConsensusPOA_ConfigureFunctionAddressAdvancedFunction

func ContractConsensusPOA_ConfigureFunctionAddressAdvancedFunction() string

func ContractConsensusPOA_ConfigureFunctionAddressFunction

func ContractConsensusPOA_ConfigureFunctionAddressFunction() string

func ContractConsensusPOA_ConfigureFunctionAddressSuperFunction

func ContractConsensusPOA_ConfigureFunctionAddressSuperFunction() string

func ContractConsensusPOA_ConfigureFunctionRoleAdvancedFunction

func ContractConsensusPOA_ConfigureFunctionRoleAdvancedFunction() string

func ContractConsensusPOA_ConfigureFunctionRoleFunction

func ContractConsensusPOA_ConfigureFunctionRoleFunction() string

func ContractConsensusPOA_ConfigureFunctionRoleSuperFunction

func ContractConsensusPOA_ConfigureFunctionRoleSuperFunction() string

func ContractConsensusPOA_GetAddressRolesMapFunction

func ContractConsensusPOA_GetAddressRolesMapFunction() string

func ContractConsensusPOA_GetAdminsAndValidatorsFunction

func ContractConsensusPOA_GetAdminsAndValidatorsFunction() string

func ContractConsensusPOA_GetSignupValidatorsFunction

func ContractConsensusPOA_GetSignupValidatorsFunction() string

func ContractConsensusPOA_InitFunction

func ContractConsensusPOA_InitFunction() string

func ContractConsensusPOA_TransferAssetFunction

func ContractConsensusPOA_TransferAssetFunction() string

func ContractConsensusPOA_UpdateValidatorsBlockInfoFunction

func ContractConsensusPOA_UpdateValidatorsBlockInfoFunction() string

func ContractConsensusSatoshiPlus_GetSignupValidatorsFunction

func ContractConsensusSatoshiPlus_GetSignupValidatorsFunction() string

func ContractConsensusSatoshiPlus_GetValidatorBlockInfoFunction

func ContractConsensusSatoshiPlus_GetValidatorBlockInfoFunction() string

func ContractConsensusSatoshiPlus_InitFunction

func ContractConsensusSatoshiPlus_InitFunction() string

func ContractConsensusSatoshiPlus_SignupFunction

func ContractConsensusSatoshiPlus_SignupFunction() string

func ContractConsensusSatoshiPlus_UpdateValidatorsBlockInfoFunction

func ContractConsensusSatoshiPlus_UpdateValidatorsBlockInfoFunction() string

func ContractGenesisOrganization_ExistedFunction

func ContractGenesisOrganization_ExistedFunction() string

func ContractGenesisOrganization_InitFunction

func ContractGenesisOrganization_InitFunction() string

func ContractGenesisOrganization_StartProposalFunction

func ContractGenesisOrganization_StartProposalFunction() string

func ContractGenesisOrganization_VoteFunction

func ContractGenesisOrganization_VoteFunction() string

func ContractRegistryCenter_BurnAssetFunction

func ContractRegistryCenter_BurnAssetFunction() string

func ContractRegistryCenter_CloseOrganizationFunction

func ContractRegistryCenter_CloseOrganizationFunction() string

func ContractRegistryCenter_CreateFunction

func ContractRegistryCenter_CreateFunction() string

func ContractRegistryCenter_DeactivateTemplateFunction

func ContractRegistryCenter_DeactivateTemplateFunction() string

func ContractRegistryCenter_FindAssetFunction

func ContractRegistryCenter_FindAssetFunction() string

func ContractRegistryCenter_GetAssetInfoByAssetIdFunction

func ContractRegistryCenter_GetAssetInfoByAssetIdFunction() string

func ContractRegistryCenter_GetOrganizationAddressByIdFunction

func ContractRegistryCenter_GetOrganizationAddressByIdFunction() string

func ContractRegistryCenter_GetOrganizationAddressesByAssetsFunction

func ContractRegistryCenter_GetOrganizationAddressesByAssetsFunction() string

func ContractRegistryCenter_GetOrganizationIdFunction

func ContractRegistryCenter_GetOrganizationIdFunction() string

func ContractRegistryCenter_HasRegisteredFunction

func ContractRegistryCenter_HasRegisteredFunction() string

func ContractRegistryCenter_InitFunction

func ContractRegistryCenter_InitFunction() string

func ContractRegistryCenter_IsRestrictedAssetFunction

func ContractRegistryCenter_IsRestrictedAssetFunction() string

func ContractRegistryCenter_MintAssetFunction

func ContractRegistryCenter_MintAssetFunction() string

func ContractRegistryCenter_NewAssetInfoFunction

func ContractRegistryCenter_NewAssetInfoFunction() string

func ContractRegistryCenter_RegisterOrganizationFunction

func ContractRegistryCenter_RegisterOrganizationFunction() string

func ContractRegistryCenter_RemoveAssetRestrictionFunction

func ContractRegistryCenter_RemoveAssetRestrictionFunction() string

func ContractRegistryCenter_RenameOrganizationFunction

func ContractRegistryCenter_RenameOrganizationFunction() string

func ContractRegistryCenter_UpdateOrganizationStatusFunction

func ContractRegistryCenter_UpdateOrganizationStatusFunction() string

func ContractTemplateWarehouse_ALL_APPROVERFunction

func ContractTemplateWarehouse_ALL_APPROVERFunction() string

func ContractTemplateWarehouse_CreateFunction

func ContractTemplateWarehouse_CreateFunction() string

func ContractTemplateWarehouse_DisableFunction

func ContractTemplateWarehouse_DisableFunction() string

func ContractTemplateWarehouse_EnableFunction

func ContractTemplateWarehouse_EnableFunction() string

func ContractTemplateWarehouse_GetApprovedTemplateFunction

func ContractTemplateWarehouse_GetApprovedTemplateFunction() string

func ContractTemplateWarehouse_GetApprovedTemplatesCountFunction

func ContractTemplateWarehouse_GetApprovedTemplatesCountFunction() string

func ContractTemplateWarehouse_GetSubmittedTemplateFunction

func ContractTemplateWarehouse_GetSubmittedTemplateFunction() string

func ContractTemplateWarehouse_GetSubmittedTemplatesCountFunction

func ContractTemplateWarehouse_GetSubmittedTemplatesCountFunction() string

func ContractTemplateWarehouse_GetTemplateFunction

func ContractTemplateWarehouse_GetTemplateFunction() string

func ContractTemplateWarehouse_InitFunction

func ContractTemplateWarehouse_InitFunction() string

func ContractTemplateWarehouse_NameExistFunction

func ContractTemplateWarehouse_NameExistFunction() string

func ContractTemplateWarehouse_THRESHOLDFunction

func ContractTemplateWarehouse_THRESHOLDFunction() string

func ContractValidatorCommittee_CanPerformFunction

func ContractValidatorCommittee_CanPerformFunction() string

func ContractValidatorCommittee_ConfigureAddressRoleFunction

func ContractValidatorCommittee_ConfigureAddressRoleFunction() string

func ContractValidatorCommittee_ConfigureFunctionAddressAdvancedFunction

func ContractValidatorCommittee_ConfigureFunctionAddressAdvancedFunction() string

func ContractValidatorCommittee_ConfigureFunctionAddressFunction

func ContractValidatorCommittee_ConfigureFunctionAddressFunction() string

func ContractValidatorCommittee_ConfigureFunctionAddressSuperFunction

func ContractValidatorCommittee_ConfigureFunctionAddressSuperFunction() string

func ContractValidatorCommittee_ConfigureFunctionRoleAdvancedFunction

func ContractValidatorCommittee_ConfigureFunctionRoleAdvancedFunction() string

func ContractValidatorCommittee_ConfigureFunctionRoleFunction

func ContractValidatorCommittee_ConfigureFunctionRoleFunction() string

func ContractValidatorCommittee_ConfigureFunctionRoleSuperFunction

func ContractValidatorCommittee_ConfigureFunctionRoleSuperFunction() string

func ContractValidatorCommittee_GetAddressRolesMapFunction

func ContractValidatorCommittee_GetAddressRolesMapFunction() string

func ContractValidatorCommittee_GetAssetFeeListFunction

func ContractValidatorCommittee_GetAssetFeeListFunction() string

func ContractValidatorCommittee_GetRoundLastUpdateHeightFunction

func ContractValidatorCommittee_GetRoundLastUpdateHeightFunction() string

func ContractValidatorCommittee_InitFunction

func ContractValidatorCommittee_InitFunction() string

func ContractValidatorCommittee_SignupFunction

func ContractValidatorCommittee_SignupFunction() string

func ContractValidatorCommittee_StartNewRoundFunction

func ContractValidatorCommittee_StartNewRoundFunction() string

func ContractValidatorCommittee_StartProposalFunction

func ContractValidatorCommittee_StartProposalFunction() string

func ContractValidatorCommittee_VoteFunction

func ContractValidatorCommittee_VoteFunction() string

func CopyBytes

func CopyBytes(b []byte) (copiedBytes []byte)

CopyBytes returns an exact copy of the provided bytes.

func Decode

func Decode(dst *Hash, src string) error

Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.

func DoubleHashB

func DoubleHashB(b []byte) []byte

DoubleHashB calculates hash(hash(b)) and returns the resulting bytes.

func FromHex

func FromHex(s string) []byte

FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func GetConsensus

func GetConsensus(name string) int32

GetConsensus returns consensus type according to the given name

func Hash160

func Hash160(buf []byte) []byte

Hash160 calculates the hash ripemd160(sha256(b)).

func HashB

func HashB(b []byte) []byte

HashB calculates hash(b) and returns the resulting bytes.

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func IsDeserializeErr

func IsDeserializeErr(err error) bool

IsDeserializeErr returns whether or not the passed error is an DeserializeError error.

func IsHexAddress

func IsHexAddress(s string) bool

IsHexAddress verifies whether a string can represent a valid hex-encoded Ethereum address or not.

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

LeftPadBytes zero-pads slice to the left up to length l.

func PackCanTransferInput

func PackCanTransferInput(transferAddress []byte, assetIndex uint32) []byte

PackCanTransferInput returns a byte slice according to given parameters

func PackGetOrganizationAddressByIdInput

func PackGetOrganizationAddressByIdInput(organizationId uint32, assetIndex uint32) []byte

PackGetOrganizationAddressByIdInput returns a byte slice according to given parameters

func PackGetTemplateCountInput

func PackGetTemplateCountInput(funcName string, category uint16) []byte

PackGetTemplateCountInput returns a byte slice according to given parameters

func PackGetTemplateDetailInput

func PackGetTemplateDetailInput(funcName string, category uint16, index uint64) []byte

PackGetTemplateDetailInput returns a byte slice according to given parameters

func PackGetTemplateInput

func PackGetTemplateInput(category uint16, name string) []byte

PackGetTemplateInput returns a byte slice according to given parameters

func PackIsRestrictedAssetInput

func PackIsRestrictedAssetInput(organizationId uint32, assetIndex uint32) []byte

PackIsRestrictedAssetInput returns a byte slice according to given parameters

func RightPadBytes

func RightPadBytes(slice []byte, l int) []byte

RightPadBytes zero-pads slice to the right up to length l.

func UnPackBoolResult

func UnPackBoolResult(ret []byte) (bool, error)

UnPackBoolResult returns bool value by unpacking given byte slice

func UnPackGetTemplateDetailResult

func UnPackGetTemplateDetailResult(ret []byte) (string, []byte, int64, uint8, uint8, uint8, uint8, error)

UnPackGetTemplateDetailResult returns template detail by unpacking given byte slice

func UnPackGetTemplatesCountResult

func UnPackGetTemplatesCountResult(ret []byte) (uint64, error)

UnPackGetTemplatesCountResult returns template number by unpacking given byte slice

func UnPackIsRestrictedAssetResult

func UnPackIsRestrictedAssetResult(ret []byte) (bool, bool, error)

UnPackBoolResult returns bool value by unpacking given byte slice

Types

type Address

type Address [AddressLength]byte

Address represents the 21 byte address of an Ethereum account.

func BigToAddress

func BigToAddress(b *big.Int) Address

BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.

func BytesToAddress

func BytesToAddress(b []byte) Address

BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.

func HexToAddress

func HexToAddress(s string) Address

HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.

func NewAddress

func NewAddress(b []byte) (*Address, error)

func NewAddressWithId

func NewAddressWithId(netId byte, b []byte) (*Address, error)

func (Address) Big

func (a Address) Big() *big.Int

Big converts an address to a big integer.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes gets the string representation of the underlying address.

func (*Address) EncodeAddress

func (a *Address) EncodeAddress() string

Implement for IAddress EncodeAddress returns the string encoding of a pay-to-pubkey-hash address. Part of the Address interface.

func (Address) Format

func (a Address) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Address) Hash

func (a Address) Hash() Hash

Hash converts an address to a hash by left-padding it with zeros.

func (Address) Hex

func (a Address) Hex() string

Hex returns an EIP55-compliant hex string representation of the address.

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

MarshalText returns the hex representation of a.

func (*Address) Scan

func (a *Address) Scan(src interface{}) error

Scan implements Scanner for database/sql.

func (*Address) ScriptAddress

func (a *Address) ScriptAddress() []byte

ScriptAddress returns the bytes to be included in a txout script to pay to a pubkey hash. Part of the Address interface.

func (*Address) SetBytes

func (a *Address) SetBytes(b []byte)

SetBytes sets the address to the value of b. If b is larger than len(a) it will panic.

func (*Address) StandardAddress

func (a *Address) StandardAddress() [AddressLength]byte

func (Address) String

func (a Address) String() string

String implements fmt.Stringer.

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Address) Value

func (a Address) Value() (driver.Value, error)

Value implements valuer for database/sql.

type AddressList

type AddressList []Address

func (AddressList) Len

func (al AddressList) Len() int

func (AddressList) Less

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

func (AddressList) Swap

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

type Amount

type Amount int64

Amount describes a method of converting an Amount to something other than the base unit of an asimov.

func (Amount) String

func (u Amount) String() string

String returns the unit as a string. For recognized units, the SI prefix is used, or "Xing" for the base unit.

type AsimovNet

type AsimovNet uint32

AsimovNet represents which asimov network a message belongs to.

const (
	// MainNet represents the main asimov network.
	MainNet AsimovNet = 0xd9b4bef9

	// DevelopNet represents the regression test network.
	DevelopNet AsimovNet = 0x39b187f3

	// TestNet represents the test network.
	TestNet AsimovNet = 0x0709110b
)

Constants used to indicate the message asimov network. They can also be used to seek to the next message when a stream's state is unknown, but this package does not provide that functionality since it's generally a better idea to simply disconnect clients that are misbehaving over TCP.

func (AsimovNet) String

func (n AsimovNet) String() string

String returns the types.AsimovNet in human-readable form.

type AssertError

type AssertError string

AssertError identifies an error that indicates an internal code consistency issue and should be treated as a critical and unrecoverable error.

func (AssertError) Error

func (e AssertError) Error() string

Error returns the assertion error as a human-readable string and satisfies the error interface.

type BehaviorFlags

type BehaviorFlags uint32

BehaviorFlags is a bitmask defining tweaks to the normal behavior when performing chain processing and consensus rules checks.

const (
	// BFFastAdd may be set to indicate that several checks can be avoided
	// for the block since it is already known to fit into the chain due to
	// already proving it correct links into the chain up to a known
	// state db.  This is primarily used for miner.
	BFFastAdd BehaviorFlags = 1 << iota

	// BFNone is a convenience value to specifically indicate no flags.
	BFNone BehaviorFlags = 0
)

type DeserializeError

type DeserializeError string

DeserializeError signifies that a problem was encountered when deserializing data.

func (DeserializeError) Error

func (e DeserializeError) Error() string

Error implements the error interface.

type Hash

type Hash [HashLength]byte

Hash represents the 32 byte Keccak256 hash of arbitrary data.

func BigToHash

func BigToHash(b *big.Int) Hash

BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func DoubleHashH

func DoubleHashH(b []byte) Hash

DoubleHashH calculates hash(hash(b)) and returns the resulting bytes as a Hash.

func HashH

func HashH(b []byte) Hash

HashH calculates hash(b) and returns the resulting bytes as a Hash.

func HexToHash

func HexToHash(s string) Hash

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func NewHashFromStr

func NewHashFromStr(hash string) (*Hash, error)

NewHashFromStr creates a Hash from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the Hash.

func (Hash) Big

func (h Hash) Big() *big.Int

Big converts a hash to a big integer.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (*Hash) CloneBytes

func (h *Hash) CloneBytes() []byte

CloneBytes returns a copy of the bytes which represent the hash as a byte slice.

NOTE: It is generally cheaper to just slice the hash directly thereby reusing the same bytes rather than calling this method.

func (Hash) Generate

func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value

Generate implements testing/quick.Generator.

func (Hash) Hex

func (h Hash) Hex() string

Hex converts a hash to a hex string.

func (*Hash) IsEqual

func (h *Hash) IsEqual(target *Hash) bool

IsEqual returns true if target is the same as hash.

func (Hash) MarshalText

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

MarshalText returns the hex representation of h.

func (*Hash) Scan

func (h *Hash) Scan(src interface{}) error

Scan implements Scanner for database/sql.

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (Hash) String

func (h Hash) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash) TerminalString

func (h Hash) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Hash) UnprefixString

func (h Hash) UnprefixString() string

UnprefixString returns unprefix hex string.

func (Hash) Value

func (h Hash) Value() (driver.Value, error)

Value implements valuer for database/sql.

type IAddress

type IAddress interface {
	// String returns the string encoding of the transaction output
	// destination.
	//
	// Please note that String differs subtly from EncodeAddress: String
	// will return the value as a string without any conversion, while
	// EncodeAddress may convert destination types (for example,
	// converting pubkeys to P2PKH addresses) before encoding as a
	// payment address string.
	String() string

	// EncodeAddress returns the string encoding of the payment address
	// associated with the Address value.  See the comment on String
	// for how this method differs from String.
	EncodeAddress() string

	//21 bytes
	StandardAddress() [AddressLength]byte

	// ScriptAddress returns the raw bytes of the address to be used
	// when inserting the address into a txout's script.
	ScriptAddress() []byte
}

Address is an interface type for any type of destination a transaction output may spend to. This includes pay-to-pubkey (P2PK), pay-to-pubkey-hash (P2PKH), and pay-to-script-hash (P2SH). Address is designed to be generic enough that other kinds of addresses may be added in the future without changing the decoding and encoding API.

type MixedcaseAddress

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

MixedcaseAddress retains the original string, which may or may not be correctly checksummed

func (*MixedcaseAddress) Address

func (ma *MixedcaseAddress) Address() Address

Address returns the address

func (*MixedcaseAddress) MarshalJSON

func (ma *MixedcaseAddress) MarshalJSON() ([]byte, error)

MarshalJSON marshals the original value

func (*MixedcaseAddress) Original

func (ma *MixedcaseAddress) Original() string

Original returns the mixed-case input string

func (*MixedcaseAddress) String

func (ma *MixedcaseAddress) String() string

String implements fmt.Stringer

func (*MixedcaseAddress) UnmarshalJSON

func (ma *MixedcaseAddress) UnmarshalJSON(input []byte) error

UnmarshalJSON parses MixedcaseAddress

func (*MixedcaseAddress) ValidChecksum

func (ma *MixedcaseAddress) ValidChecksum() bool

ValidChecksum returns true if the address has valid checksum

type ServiceFlag

type ServiceFlag uint64

ServiceFlag identifies services supported by a bitcoin peer.

const (
	// SFNodeNetwork is a flag used to indicate a peer is a full node.
	SFNodeNetwork ServiceFlag = 1 << iota

	// SFNodeBloom is a flag used to indicate a peer supports bloom
	// filtering.
	SFNodeBloom

	// SFNodeCF is a flag used to indicate a peer supports committed
	// filters (CFs).
	SFNodeCF
)

func (ServiceFlag) String

func (f ServiceFlag) String() string

String returns the ServiceFlag in human-readable form.

type StorageSize

type StorageSize float64

StorageSize is a wrapper around a float value that supports user friendly formatting.

func (StorageSize) String

func (s StorageSize) String() string

String implements the stringer interface.

func (StorageSize) TerminalString

func (s StorageSize) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

type UnprefixedAddress

type UnprefixedAddress Address

UnprefixedAddress allows marshaling an Address without 0x prefix.

func (UnprefixedAddress) MarshalText

func (a UnprefixedAddress) MarshalText() ([]byte, error)

MarshalText encodes the address as hex.

func (*UnprefixedAddress) UnmarshalText

func (a *UnprefixedAddress) UnmarshalText(input []byte) error

UnmarshalText decodes the address from hex. The 0x prefix is optional.

type UnprefixedHash

type UnprefixedHash Hash

UnprefixedHash allows marshaling a Hash without 0x prefix.

func (UnprefixedHash) MarshalText

func (h UnprefixedHash) MarshalText() ([]byte, error)

MarshalText encodes the hash as hex.

func (*UnprefixedHash) UnmarshalText

func (h *UnprefixedHash) UnmarshalText(input []byte) error

UnmarshalText decodes the hash from hex. The 0x prefix is optional.

Directories

Path Synopsis
Package base58 provides an API for working with modified base58 and Base58Check encodings.
Package base58 provides an API for working with modified base58 and Base58Check encodings.
Package bech32 provides a Go implementation of the bech32 format specified in BIP 173.
Package bech32 provides a Go implementation of the bech32 format specified in BIP 173.
Package hexutil implements hex encoding with 0x prefix.
Package hexutil implements hex encoding with 0x prefix.

Jump to

Keyboard shortcuts

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