massutil

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	// witness v0 address = 0x00 << 2 | 0x00
	// StandardVersion              = 0x0000
	AddressClassWitnessV0 uint16 = 0x0000

	// witness staking address = 0x00 << 2 | 0x01
	// StakingTxVersion                  = 0x0001
	AddressClassWitnessStaking uint16 = 0x0001
)

address version is resulted from:

(witness verison) << 2 | (witness extension version)
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 (
	// ErrChecksumMismatch describes an error where decoding failed due
	// to a bad checksum.
	ErrChecksumMismatch = errors.New("checksum mismatch")

	// 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 config.Register) network.
	ErrUnknownAddressType = errors.New("unknown address type")

	// ErrAddressCollision describes an error where an address can not
	// be uniquely determined as either a pay-to-pubkey-hash or
	// pay-to-script-hash address since the leading identifier is used for
	// describing both address kinds, but for different networks.  Rather
	// than assuming or defaulting to one or the other, this error is
	// returned and the caller must decide how to decode the address.
	ErrAddressCollision = errors.New("address collision")
)
View Source
var (
	ErrInvalidFloat = errors.New("invalid float")
	ErrMaxAmount    = errors.New("exceed maximum amount")
)
View Source
var WitPkScriptParseFunc func(script []byte) (class byte, frozen uint64, scriptHash [32]byte, boundPkScript []byte)

Registered by txscript

Functions

func GetBindingTarget

func GetBindingTarget(pub []byte, proofType poc.ProofType, bitLength int) (string, error)

GetBindingTarget returns the binding target for plots. For native MassDB, pub should be the SerializeCompressed PublicKey. For Chia Plot, pub should be the 32-byte PlotID.

func GetChiaPlotBindingTarget

func GetChiaPlotBindingTarget(plotID pocutil.Hash, k int) (string, error)

func GetMassDBBindingTarget

func GetMassDBBindingTarget(pubKey *pocec.PublicKey, bitLength int) (string, error)

func Hash160

func Hash160(data []byte) []byte

Hash160 returns ripemd160(sha256(b)).

Example
data := []byte("test hash160")
fmt.Println(hex.EncodeToString(Hash160(data)))
Output:

b720061a734285a70e86cb32b31f32884e198c32

func Hash256

func Hash256(data []byte) []byte

Hash256 returns sha256(sha256(data))

Example
data := []byte("test hash256")
fmt.Println(hex.EncodeToString(Hash256(data)))
Output:

cb43cc5fc9e305ddf8fccc2112629da4d21fc840937b785e86d4a220406359a8

func IsAddressPubKeyHash

func IsAddressPubKeyHash(ad interface{}) bool

func IsValidAddressClass

func IsValidAddressClass(class uint16) bool

func IsValidBindingTarget

func IsValidBindingTarget(target Address) bool

func IsWitnessStakingAddress

func IsWitnessStakingAddress(ad interface{}) bool

func IsWitnessV0Address

func IsWitnessV0Address(ad interface{}) bool

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.

func Ripemd160

func Ripemd160(data []byte) []byte

Ripemd160 return ripemd16(data)

Example
data := []byte("test hash256")
fmt.Println(hex.EncodeToString(Ripemd160(data)))
Output:

07fc1824f3c8b5c0aebfe9edd7b519a85def76eb

func Sha256

func Sha256(data []byte) []byte

Sha256 returns sha256(data)

Example
data := []byte("test hash256")
fmt.Println(hex.EncodeToString(Sha256(data)))
Output:

de8503647d0760bbabc8bf47526176bd1046afa9f5f20d8831d0ff455cee0523

func TstSetMaxAmount

func TstSetMaxAmount(mass float64)

TstSetMaxAmount For testing purpose

func TstSetMinRelayTxFee

func TstSetMinRelayTxFee(fee uint64)

TstSetMinRelayTxFee For testing purposes

Types

type Address

type Address 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

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

	// IsForNet returns whether or not the address is associated with the
	// passed Mass network.
	IsForNet(*config.Params) bool
}

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.

func DecodeAddress

func DecodeAddress(addr string, defaultNet *config.Params) (Address, 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 Mass 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 NewAddressesFromStringList

func NewAddressesFromStringList(strList []string, net *config.Params) ([]Address, error)

type AddressBindingTarget

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

AddressBindingTarget is used since MASS IP2

func NewAddressBindingTarget

func NewAddressBindingTarget(serialized []byte, net *config.Params) (*AddressBindingTarget, error)

func (*AddressBindingTarget) EncodeAddress

func (a *AddressBindingTarget) EncodeAddress() string

func (*AddressBindingTarget) IsForNet

func (a *AddressBindingTarget) IsForNet(net *config.Params) bool

func (*AddressBindingTarget) ScriptAddress

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

func (*AddressBindingTarget) String

func (a *AddressBindingTarget) String() string

type AddressPubKey

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

AddressPubKey is an Address for a pay-to-pubkey transaction.

func NewAddressPubKey

func NewAddressPubKey(serializedPubKey []byte, net *config.Params) (*AddressPubKey, error)

NewAddressPubKey returns a new AddressPubKey which represents a pay-to-pubkey address. The serializedPubKey parameter must be a valid pubkey and can be uncompressed, compressed, or hybrid.

func (*AddressPubKey) AddressPubKeyHash

func (a *AddressPubKey) AddressPubKeyHash() *AddressPubKeyHash

AddressPubKeyHash returns the pay-to-pubkey address converted to a pay-to-pubkey-hash address. Note that the public key format (uncompressed, compressed, etc) will change the resulting address. This is expected since pay-to-pubkey-hash is a hash of the serialized public key which obviously differs with the format. At the time of this writing, most Mass addresses are pay-to-pubkey-hash constructed from the uncompressed public key.

func (*AddressPubKey) EncodeAddress

func (a *AddressPubKey) EncodeAddress() string

EncodeAddress returns the string encoding of the public key as a pay-to-pubkey-hash. Note that the public key format (uncompressed, compressed, etc) will change the resulting address. This is expected since pay-to-pubkey-hash is a hash of the serialized public key which obviously differs with the format. At the time of this writing, most Mass addresses are pay-to-pubkey-hash constructed from the uncompressed public key.

Part of the Address interface.

func (*AddressPubKey) Format

func (a *AddressPubKey) Format() PubKeyFormat

Format returns the format (uncompressed, compressed, etc) of the pay-to-pubkey address.

func (*AddressPubKey) IsForNet

func (a *AddressPubKey) IsForNet(net *config.Params) bool

IsForNet returns whether or not the pay-to-pubkey address is associated with the passed Mass network.

func (*AddressPubKey) PubKey

func (a *AddressPubKey) PubKey() *btcec.PublicKey

PubKey returns the underlying public key for the address.

func (*AddressPubKey) ScriptAddress

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

ScriptAddress returns the bytes to be included in a txout script to pay to a public key. Setting the public key format will affect the output of this function accordingly. Part of the Address interface.

func (*AddressPubKey) SetFormat

func (a *AddressPubKey) SetFormat(pkFormat PubKeyFormat)

SetFormat sets the format (uncompressed, compressed, etc) of the pay-to-pubkey address.

func (*AddressPubKey) String

func (a *AddressPubKey) String() string

String returns the hex-encoded human-readable string for the pay-to-pubkey address. This is not the same as calling EncodeAddress.

type AddressPubKeyHash

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

AddressPubKeyHash is an Address for a pay-to-pubkey-hash (P2PKH) transaction.

func NewAddressPubKeyHash

func NewAddressPubKeyHash(pkHash []byte, net *config.Params) (*AddressPubKeyHash, error)

NewAddressPubKeyHash returns a new AddressPubKeyHash. pkHash mustbe 20 bytes.

func (*AddressPubKeyHash) EncodeAddress

func (a *AddressPubKeyHash) EncodeAddress() string

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

func (*AddressPubKeyHash) Hash160

func (a *AddressPubKeyHash) Hash160() *[ripemd160.Size]byte

Hash160 returns the underlying array of the pubkey hash. This can be useful when an array is more appropiate than a slice (for example, when used as map keys).

func (*AddressPubKeyHash) IsForNet

func (a *AddressPubKeyHash) IsForNet(net *config.Params) bool

IsForNet returns whether or not the pay-to-pubkey-hash address is associated with the passed Mass network.

func (*AddressPubKeyHash) ScriptAddress

func (a *AddressPubKeyHash) 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 (*AddressPubKeyHash) String

func (a *AddressPubKeyHash) String() string

String returns a human-readable string for the pay-to-pubkey-hash address. This is equivalent to calling EncodeAddress, but is provided so the type can be used as a fmt.Stringer.

type AddressScriptHash

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

AddressScriptHash is an Address for a pay-to-script-hash (P2SH) transaction.

func NewAddressScriptHash

func NewAddressScriptHash(serializedScript []byte, net *config.Params) (*AddressScriptHash, error)

NewAddressScriptHash returns a new AddressScriptHash.

func NewAddressScriptHashFromHash

func NewAddressScriptHashFromHash(scriptHash []byte, net *config.Params) (*AddressScriptHash, error)

NewAddressScriptHashFromHash returns a new AddressScriptHash. scriptHash must be 20 bytes.

func (*AddressScriptHash) EncodeAddress

func (a *AddressScriptHash) EncodeAddress() string

EncodeAddress returns the string encoding of a pay-to-script-hash address. Part of the Address interface.

func (*AddressScriptHash) Hash160

func (a *AddressScriptHash) Hash160() *[ripemd160.Size]byte

Hash160 returns the underlying array of the script hash. This can be useful when an array is more appropiate than a slice (for example, when used as map keys).

func (*AddressScriptHash) IsForNet

func (a *AddressScriptHash) IsForNet(net *config.Params) bool

IsForNet returns whether or not the pay-to-script-hash address is associated with the passed Mass network.

func (*AddressScriptHash) ScriptAddress

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

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

func (*AddressScriptHash) String

func (a *AddressScriptHash) String() string

String returns a human-readable string for the pay-to-script-hash address. This is equivalent to calling EncodeAddress, but is provided so the type can be used as a fmt.Stringer.

type AddressWitnessScriptHash

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

AddressWitnessScriptHash is an Address for a pay-to-witness-script-hash (P2WSH) output. See BIP 173 for further details regarding native segregated witness address encoding: https://github.com/Mass/bips/blob/master/bip-0173.mediawiki

func NewAddressStakingScriptHash

func NewAddressStakingScriptHash(witnessProg []byte, net *config.Params) (*AddressWitnessScriptHash, error)

NewAddressStakingScriptHash returns a new Address for loctime transaction

func NewAddressWitnessScriptHash

func NewAddressWitnessScriptHash(witnessProg []byte, net *config.Params) (*AddressWitnessScriptHash, error)

NewAddressWitnessScriptHash returns a new AddressWitnessPubKeyHash.

func (*AddressWitnessScriptHash) EncodeAddress

func (a *AddressWitnessScriptHash) EncodeAddress() string

EncodeAddress returns the bech32 string encoding of an AddressWitnessScriptHash. Part of the Address interface.

func (*AddressWitnessScriptHash) Hrp

Hrp returns the human-readable part of the bech32 encoded AddressWitnessScriptHash.

func (*AddressWitnessScriptHash) IsForNet

func (a *AddressWitnessScriptHash) IsForNet(net *config.Params) bool

IsForNet returns whether or not the AddressWitnessScriptHash is associated with the passed Mass network. Part of the Address interface.

func (*AddressWitnessScriptHash) ScriptAddress

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

ScriptAddress returns the witness program for this address. Part of the Address interface.

func (*AddressWitnessScriptHash) String

func (a *AddressWitnessScriptHash) String() string

String returns a human-readable string for the AddressWitnessScriptHash. This is equivalent to calling EncodeAddress, but is provided so the type can be used as a fmt.Stringer. Part of the Address interface.

func (*AddressWitnessScriptHash) WitnessExtendVersion

func (a *AddressWitnessScriptHash) WitnessExtendVersion() byte

func (*AddressWitnessScriptHash) WitnessProgram

func (a *AddressWitnessScriptHash) WitnessProgram() []byte

WitnessProgram returns the witness program of the AddressWitnessScriptHash.

func (*AddressWitnessScriptHash) WitnessVersion

func (a *AddressWitnessScriptHash) WitnessVersion() byte

WitnessVersion returns the witness version of the AddressWitnessScriptHash.

type Amount

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

Amount represents the base Mass monetary unit (colloquially referred to as a `Maxwell'). A single Amount is equal to 1e-8 of a Mass. The value is limited in range [0, consensus.MaxMass * consensus.MaxwellPerMass]

Example
package main

import (
	"fmt"

	"github.com/gnc-project/mass-core/massutil"
)

func main() {

	a := massutil.ZeroAmount()
	fmt.Println("Zero Maxwell:", a)

	a, _ = massutil.NewAmountFromUint(100000000)
	fmt.Println("100,000,000 Maxwells:", a)

	a, _ = massutil.NewAmountFromUint(100000)
	fmt.Println("100,000 Maxwells:", a)
}
Output:

Zero Maxwell: 0 MASS
100,000,000 Maxwells: 1 MASS
100,000 Maxwells: 0.001 MASS
Example (UnitConversions)
package main

import (
	"fmt"

	"github.com/gnc-project/mass-core/massutil"
)

func main() {
	amount, _ := massutil.NewAmountFromUint(44433322211100)

	fmt.Println("Maxwell to kMASS:", amount.Format(massutil.AmountKiloMASS))
	fmt.Println("Maxwell to MASS:", amount)
	fmt.Println("Maxwell to MilliMASS:", amount.Format(massutil.AmountMilliMASS))
	fmt.Println("Maxwell to MicroMASS:", amount.Format(massutil.AmountMicroMASS))
	fmt.Println("Maxwell to Maxwell:", amount.Format(massutil.AmountMaxwell))

}
Output:

Maxwell to kMASS: 444.333222111 kMASS
Maxwell to MASS: 444333.222111 MASS
Maxwell to MilliMASS: 444333222.111 mMASS
Maxwell to MicroMASS: 444333222111 μMASS
Maxwell to Maxwell: 44433322211100 Maxwell

func MaxAmount

func MaxAmount() Amount

MaxAmount is the maximum transaction amount allowed in maxwell.

func MinRelayTxFee

func MinRelayTxFee() Amount

MinRelayTxFee is the minimum fee required for relaying tx.

func NewAmount

func NewAmount(u *safetype.Uint128) (Amount, error)

func NewAmountFromInt

func NewAmountFromInt(i int64) (Amount, error)

func NewAmountFromMass

func NewAmountFromMass(f float64) (Amount, error)

NewAmountFromMass creates an Amount from a floating point value representing some value in Mass. NewAmountFromMass errors if f is NaN or +-Infinity, but does not check that the amount is within the total amount of Mass producible as f may not refer to an amount at a single moment in time.

NewAmountFromMass is for specifically for converting MASS to Maxwell. For creating a new Amount with an int64 value which denotes a quantity of Maxwell, do a simple type conversion from type int64 to Amount.

Example
package main

import (
	"fmt"
	"math"

	"github.com/gnc-project/mass-core/massutil"
)

func main() {
	amountOne, err := massutil.NewAmountFromMass(1)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(amountOne) //Output 1

	amountFraction, err := massutil.NewAmountFromMass(0.01234567)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(amountFraction) //Output 2

	amountZero, err := massutil.NewAmountFromMass(0)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(amountZero) //Output 3

	amountNaN, err := massutil.NewAmountFromMass(math.NaN())
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(amountNaN) //Output 4

}
Output:

1 MASS
0.01234567 MASS
0 MASS
invalid float

func NewAmountFromUint

func NewAmountFromUint(i uint64) (Amount, error)

func ZeroAmount

func ZeroAmount() Amount

func (Amount) Add

func (a Amount) Add(b Amount) (Amount, error)

func (Amount) AddInt

func (a Amount) AddInt(i int64) (Amount, error)

func (Amount) Cmp

func (a Amount) Cmp(b Amount) int

func (Amount) Format

func (a Amount) Format(u AmountUnit) string

Format formats a monetary amount counted in Mass base units as a string for a given unit. The conversion will succeed for any unit, however, known units will be formated with an appended label describing the units with SI notation, or "Maxwell" for the base unit.

func (Amount) IntValue

func (a Amount) IntValue() int64

func (Amount) IsZero

func (a Amount) IsZero() bool

func (Amount) MulF64

func (a Amount) MulF64(f float64) (Amount, error)

MulF64 multiplies an Amount by a floating point value. While this is not an operation that must typically be done by a full node or wallet, it is useful for services that build on top of Mass (for example, calculating a fee by multiplying by a percentage).

func (Amount) String

func (a Amount) String() string

String is the equivalent of calling Format with AmountMASS.

func (Amount) Sub

func (a Amount) Sub(b Amount) (Amount, error)

func (Amount) ToMASS

func (a Amount) ToMASS() float64

ToMASS is the equivalent of calling ToUnit with AmountMASS.

func (Amount) ToUnit

func (a Amount) ToUnit(u AmountUnit) float64

ToUnit converts a monetary amount counted in Mass base units to a floating point value representing an amount of Mass.

func (Amount) UintValue

func (a Amount) UintValue() uint64

func (Amount) Value

func (a Amount) Value() *safetype.Uint128

type AmountUnit

type AmountUnit int

AmountUnit describes a method of converting an Amount to something other than the base unit of a Mass. The value of the AmountUnit is the exponent component of the decadic multiple to convert from an amount in Mass to an amount counted in units.

const (
	AmountMegaMASS  AmountUnit = 6
	AmountKiloMASS  AmountUnit = 3
	AmountMASS      AmountUnit = 0
	AmountMilliMASS AmountUnit = -3
	AmountMicroMASS AmountUnit = -6
	AmountMaxwell   AmountUnit = -8
)

These constants define various units used when describing a Mass monetary amount.

func (AmountUnit) String

func (u AmountUnit) String() string

String returns the unit as a string. For recognized units, the SI prefix is used, or "Maxwell" for the base unit. For all unrecognized units, "1eN MASS" is returned, where N is the AmountUnit.

type BindingList

type BindingList struct {
	Plots        []BindingPlot `json:"plots"`
	TotalCount   uint64        `json:"total_count"`
	DefaultCount uint64        `json:"default_count"`
	ChiaCount    uint64        `json:"chia_count"`
}

func NewBindingListFromFile

func NewBindingListFromFile(filename string) (*BindingList, error)

func (*BindingList) RemoveDuplicate

func (list *BindingList) RemoveDuplicate() *BindingList

func (*BindingList) WriteToFile

func (list *BindingList) WriteToFile(filename string) error

type BindingPlot

type BindingPlot struct {
	Target string `json:"target"`
	Type   uint8  `json:"type"`
	Size   uint8  `json:"size"`
}

func (BindingPlot) Equals

func (plot BindingPlot) Equals(target BindingPlot) bool

func (BindingPlot) String

func (plot BindingPlot) String() string

type Block

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

func NewBlock

func NewBlock(msgBlock *wire.MsgBlock) *Block

NewBlock returns a new instance of a Mass block given an underlying wire.MsgBlock. See Block.

func NewBlockFromBlockAndBytes

func NewBlockFromBlockAndBytes(msgBlock *wire.MsgBlock, serializedBlock []byte, mode wire.CodecMode) *Block

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

func NewBlockFromBytes

func NewBlockFromBytes(serializedBlock []byte, mode wire.CodecMode) (*Block, error)

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

func NewBlockFromReader

func NewBlockFromReader(r io.Reader, mode wire.CodecMode) (*Block, error)

NewBlockFromReader returns a new instance of a Mass block given a Reader to deserialize the block. See Block.

func (*Block) Bytes

func (b *Block) Bytes(mode wire.CodecMode) ([]byte, error)

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

func (*Block) Hash

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

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

func (*Block) Height

func (b *Block) Height() uint64

Height 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) IsFastImport

func (b *Block) IsFastImport() bool

func (*Block) IsImport

func (b *Block) IsImport() bool

func (*Block) MsgBlock

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

MsgBlock returns the underlying wire.MsgBlock for the Block.

func (*Block) PacketSize

func (b *Block) PacketSize() int

func (*Block) ResetGenerated

func (b *Block) ResetGenerated()

func (*Block) SetHeight

func (b *Block) SetHeight(height uint64)

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

func (*Block) SetSerializedBlockDB

func (b *Block) SetSerializedBlockDB(data []byte)

func (*Block) Size

func (b *Block) Size() uint64

func (*Block) Transactions

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

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

func (*Block) Tx

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

Tx returns a wrapped transaction (massutil.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 (wire.MsgTx) from the underlying wire.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) (*wire.Hash, error)

func (*Block) TxLoc

func (b *Block) TxLoc() ([]wire.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 ImportOptions

type ImportOptions struct {
	NotRunScripts bool // for import
}

type MassDBInfoV1

type MassDBInfoV1 struct {
	PublicKey     *pocec.PublicKey
	PublicKeyHash pocutil.Hash
	BitLength     int
	Plotted       bool
}

MassDB info for native plot file.

func NewMassDBInfoV1FromFile

func NewMassDBInfoV1FromFile(plotFile string) (*MassDBInfoV1, error)

type MassDBInfoV2

type MassDBInfoV2 struct {
	PoolPublicKey   *chiapos.G1Element
	FarmerPublicKey *chiapos.G1Element
	PlotPublicKey   *chiapos.G1Element
	PlotID          pocutil.Hash
	K               int
}

MassDB info for chia plot file.

func NewMassDBInfoV2FromFile

func NewMassDBInfoV2FromFile(plotFile string) (*MassDBInfoV2, error)

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 PkScriptInfo

type PkScriptInfo struct {
	Class         byte     // txscript.ScriptClass
	ScriptHash    [32]byte // witness script hash
	FrozenPeriod  uint64   // for staking
	BoundPkScript []byte   // for binding
}

type PubKeyFormat

type PubKeyFormat int

PubKeyFormat describes what format to use for a pay-to-pubkey address.

const (
	// PKFUncompressed indicates the pay-to-pubkey address format is an
	// uncompressed public key.
	PKFUncompressed PubKeyFormat = iota

	// PKFCompressed indicates the pay-to-pubkey address format is a
	// compressed public key.
	PKFCompressed

	// PKFHybrid indicates the pay-to-pubkey address format is a hybrid
	// public key.
	PKFHybrid
)

type Tx

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

func NewTx

func NewTx(msgTx *wire.MsgTx) *Tx

NewTx returns a new instance of a Mass transaction given an underlying wire.MsgTx. See Tx.

func NewTxFromBytes

func NewTxFromBytes(serializedTx []byte, mode wire.CodecMode) (*Tx, error)

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

func NewTxFromReader

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

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

func (*Tx) Bytes

func (t *Tx) Bytes(mode wire.CodecMode) ([]byte, error)

func (*Tx) GetPkScriptInfo

func (t *Tx) GetPkScriptInfo(i int) *PkScriptInfo

func (*Tx) Hash

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

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() *wire.MsgTx

MsgTx returns the underlying wire.MsgTx for the transaction.

func (*Tx) PacketSize

func (t *Tx) PacketSize() int

func (*Tx) PlainSize

func (t *Tx) PlainSize() int

func (*Tx) SetIndex

func (t *Tx) SetIndex(index int)

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

func (*Tx) TxOut

func (t *Tx) TxOut() []*wire.TxOut

func (*Tx) WitnessHash

func (t *Tx) WitnessHash() *wire.Hash

type UnsupportedWitnessExtVerError

type UnsupportedWitnessExtVerError byte

func (UnsupportedWitnessExtVerError) Error

type UnsupportedWitnessProgLenError

type UnsupportedWitnessProgLenError int

UnsupportedWitnessProgLenError describes an error where a segwit address being decoded has an unsupported witness program length.

func (UnsupportedWitnessProgLenError) Error

type UnsupportedWitnessVerError

type UnsupportedWitnessVerError byte

UnsupportedWitnessVerError describes an error where a segwit address being decoded has an unsupported witness version.

func (UnsupportedWitnessVerError) Error

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.

Jump to

Keyboard shortcuts

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