Documentation ¶
Index ¶
- Constants
- func AddressVerPubKey() byte
- func AddressVerScript() byte
- func BytesToBool(bytes []byte) bool
- func CheckPubKeyEncoding(vchPubKey []byte, flags uint32) error
- func CheckSignatureEncoding(vchSig []byte, flags uint32) error
- func DecodeOPN(opcode byte) int
- func EncodeOPN(n int) (int, error)
- func Hash160ToAddressStr(hash160 []byte, version byte) (str string, err error)
- func InitAddressParam(addressParam *AddressParam)
- func IsMinimallyEncoded(data []byte, nMaxNumSize int64) bool
- func IsOpCodeDisabled(opCode byte, flags uint32) bool
- func MinimallyEncode(data []byte) []byte
- func ReadScript(reader io.Reader, maxAllowed uint32, fieldName string) (script []byte, err error)
- type Address
- func AddressFromHash160(hash160 []byte, version byte) (address *Address, err error)
- func AddressFromPrivateKey(priKeyStr string) (*Address, error)
- func AddressFromPublicKey(publicKey []byte) (address *Address, err error)
- func AddressFromScriptHash(script []byte) (*Address, error)
- func AddressFromString(addressStr string) (btcAddress *Address, err error)
- type AddressParam
- type Script
- func (s *Script) Bytes() []byte
- func (s *Script) CheckScriptSigStandard() (bool, string)
- func (s *Script) Decode(reader io.Reader, isCoinBase bool) (err error)
- func (s *Script) Encode(writer io.Writer) (err error)
- func (s *Script) EncodeSize() uint32
- func (s *Script) ExtractDestinations() (sType int, addresses []*Address, sigCountRequired int, err error)
- func (s *Script) GetBadOpCode() bool
- func (s *Script) GetData() []byte
- func (s *Script) GetP2SHSigOpCount(scriptSig *Script) int
- func (s *Script) GetSigOpCount(accurate bool) int
- func (s *Script) IsCommitment(data []byte) bool
- func (s *Script) IsEqual(script2 *Script) bool
- func (s *Script) IsPayToScriptHash() bool
- func (s *Script) IsPushOnly() bool
- func (s *Script) IsSpendable() bool
- func (s *Script) IsStandardScriptPubKey() (pubKeyType int, pubKeys [][]byte, isStandard bool)
- func (s *Script) IsUnspendable() bool
- func (s *Script) PushData(data []byte) error
- func (s *Script) PushInt64(n int64) error
- func (s *Script) PushMultData(data [][]byte) error
- func (s *Script) PushOpCode(n int) error
- func (s *Script) PushScriptNum(sn *ScriptNum) error
- func (s *Script) PushSingleData(data []byte) error
- func (s *Script) RemoveOpCodeByIndex(index int) *Script
- func (s *Script) RemoveOpcode(code byte) *Script
- func (s *Script) RemoveOpcodeByData(data []byte) *Script
- func (s *Script) Serialize(writer io.Writer) (err error)
- func (s *Script) SerializeSize() uint32
- func (s *Script) Size() int
- func (s *Script) Unserialize(reader io.Reader, isCoinBase bool) (err error)
- type ScriptNum
Constants ¶
const ( AddressBytesLength = 25 Hash160BytesLength = 20 PublicKeyToAddress = 0x00 ScriptToAddress = 5 )
const ( DefaultSize = 28 // MaxPubKeysPerMultiSig : maximum number of public keys per multiSig MaxPubKeysPerMultiSig = 20 // LockTimeThreshold threshold for nLockTime: below this value it is interpreted as block number, // otherwise as UNIX timestamp. Threshold is Tue Nov 5 00:53:20 1985 UTC LockTimeThreshold = 500000000 // SequenceFinal setting sequence to this value for every input in a transaction // disables nLockTime. SequenceFinal = 0xffffffff MaxScriptSize = 10000 MaxScriptElementSize = 520 MaxScriptOpCodes = 201 MaxOpsPerScript = 201 // MaxStandardScriptSigSize is // Biggest 'standard' txin is a 15-of-15 P2SH multisig with compressed // keys (remember the 520 byte limit on redeemScript size). That works // out to a (15*(33+1))+3=513 byte redeemScript, 513+1+15*(73+1)+3=1627 // bytes of scriptSig, which we round off to 1650 bytes for some minor // future-proofing. That's also enough to spend a 20-of-20 CHECKMULTISIG // scriptPubKey, though such a scriptPubKey is not considered standard. MaxStandardScriptSigSize = 1650 )
const ( // SequenceLockTimeDisableFlag below flags apply in the context of BIP 68*/ // If this flag set, CTxIn::nSequence is NOT interpreted as a // relative lock-time. */ SequenceLockTimeDisableFlag = 1 << 31 // SequenceLockTimeTypeFlag if CTxIn::nSequence encodes a relative lock-time and this flag // is set, the relative lock-time has units of 512 seconds, // otherwise it specifies blocks with a granularity of 1. SequenceLockTimeTypeFlag = 1 << 22 // SequenceLockTimeMask if CTxIn::nSequence encodes a relative lock-time, this mask is // applied to extract that lock-time from the sequence field. SequenceLockTimeMask = 0x0000ffff // SequenceLockTimeGranularity in order to use the same number of bits to encode roughly the // same wall-clock duration, and because blocks are naturally // limited to occur every 600s on average, the minimum granularity // for time-based relative lock-time is fixed at 512 seconds. // Converting from CTxIn::nSequence to seconds is performed by // multiplying by 512 = 2^9, or equivalently shifting up by // 9 bits. SequenceLockTimeGranularity = 9 )
const ( ScriptVerifyNone = 0 // Evaluate P2SH subscripts (softfork safe, BIP16). ScriptVerifyP2SH = (1 << 0) // Passing a non-strict-DER signature or one with undefined hashtype to a // checksig operation causes script failure. Evaluating a pubkey that is not // (0x04 + 64 bytes) or (0x02 or 0x03 + 32 bytes) by checksig causes script // failure. ScriptVerifyStrictEnc = (1 << 1) // Passing a non-strict-DER signature to a checksig operation causes script // failure (softfork safe, BIP62 rule 1) ScriptVerifyDersig = (1 << 2) // Passing a non-strict-DER signature or one with S > order/2 to a checksig // operation causes script failure // (softfork safe, BIP62 rule 5). ScriptVerifyLowS = (1 << 3) // verify dummy stack item consumed by CHECKMULTISIG is of zero-length // (softfork safe, BIP62 rule 7). ScriptVerifyNullDummy = (1 << 4) // Using a non-push operator in the scriptSig causes script failure // (softfork safe, BIP62 rule 2). ScriptVerifySigPushOnly = (1 << 5) // Require minimal encodings for all push operations (OP_0... OP_16, // OP_1NEGATE where possible, direct pushes up to 75 bytes, OP_PUSHDATA up // to 255 bytes, OP_PUSHDATA2 for anything larger). Evaluating any other // push causes the script to fail (BIP62 rule 3). In addition, whenever a // stack element is interpreted as a number, it must be of minimal length // (BIP62 rule 4). // (softfork safe) ScriptVerifyMinmalData = (1 << 6) // Discourage use of Nops reserved for upgrades (NOP1-10) // // Provided so that nodes can avoid accepting or mining transactions // containing executed NOP's whose meaning may change after a soft-fork, // thus rendering the script invalid; with this flag set executing // discouraged NOPs fails the script. This verification flag will never be a // mandatory flag applied to scripts in a block. NOPs that are not executed, // e.g. within an unexecuted IF ENDIF block, are *not* rejected. ScriptVerifyDiscourageUpgradableNops = (1 << 7) // Require that only a single stack element remains after evaluation. This // changes the success criterion from "At least one stack element must // remain, and when interpreted as a boolean, it must be true" to "Exactly // one stack element must remain, and when interpreted as a boolean, it must // be true". // (softfork safe, BIP62 rule 6) // Note: CLEANSTACK should never be used without P2SH or WITNESS. ScriptVerifyCleanStack = (1 << 8) // Verify CHECKLOCKTIMEVERIFY // // See BIP65 for details. ScriptVerifyCheckLockTimeVerify = (1 << 9) // support CHECKSEQUENCEVERIFY opcode // // See BIP112 for details ScriptVerifyCheckSequenceVerify = (1 << 10) // Making v1-v16 witness program non-standard // ScriptVerifyDiscourageUpgradableWitnessProgram = (1 << 12) // Segwit script only: Require the argument of OP_IF/NOTIF to be exactly // 0x01 or empty vector // ScriptVerifyMinimalIf = (1 << 13) // Signature(s) must be empty vector if an CHECK(MULTI)SIG operation failed // ScriptVerifyNullFail = (1 << 14) // Public keys in scripts must be compressed // ScriptVerifyCompressedPubkeyType = (1 << 15) // ScriptEnableSigHashForkID Do we accept signature using SIGHASH_FORKID // ScriptEnableSigHashForkID = (1 << 16) // Do we accept activate replay protection using a different fork id. // ScriptEnableReplayProtection = (1 << 17) // Enable new opcodes. // ScriptEnableMonolithOpcodes = (1 << 18) ScriptMaxOpReturnRelay uint = 223 )
* Script verification flags
const ( ScriptNonStandard = iota // ScriptPubkey and following are 'standard' transaction types: ScriptPubkey ScriptPubkeyHash ScriptHash ScriptMultiSig ScriptNullData )
const ( // MandatoryScriptVerifyFlags mandatory script verification flags that all new blocks must comply with for // them to be valid. (but old blocks may not comply with) Currently just P2SH, // but in the future other flags may be added, such as a soft-fork to enforce // strict DER encoding. // // Failing one of these tests may trigger a DoS ban - see CheckInputs() for // details. MandatoryScriptVerifyFlags uint = ScriptVerifyP2SH | ScriptVerifyStrictEnc | ScriptEnableSigHashForkID /*StandardScriptVerifyFlags standard script verification flags that standard transactions will comply * with. However scripts violating these flags may still be present in valid * blocks and we must accept those blocks. */ StandardScriptVerifyFlags uint = MandatoryScriptVerifyFlags | ScriptVerifyDersig | ScriptVerifyMinmalData | ScriptVerifyNullDummy | ScriptVerifyDiscourageUpgradableNops | ScriptVerifyCleanStack | ScriptVerifyNullFail | ScriptVerifyCheckLockTimeVerify | ScriptVerifyCheckSequenceVerify | ScriptVerifyLowS | ScriptVerifyDiscourageUpgradableWitnessProgram /*StandardNotMandatoryVerifyFlags for convenience, standard but not mandatory verify flags. */ StandardNotMandatoryVerifyFlags uint = StandardScriptVerifyFlags & (^MandatoryScriptVerifyFlags) )
const ( DefaultMaxNumSize = 4 MaxInt32 = 1<<31 - 1 MinInt32 = -1 << 31 )
const (
MaxMessagePayload = 32 * 1024 * 1024
)
Variables ¶
This section is empty.
Functions ¶
func AddressVerPubKey ¶
func AddressVerPubKey() byte
func AddressVerScript ¶
func AddressVerScript() byte
func BytesToBool ¶
func CheckPubKeyEncoding ¶
func CheckSignatureEncoding ¶
func Hash160ToAddressStr ¶
func InitAddressParam ¶ added in v0.0.3
func InitAddressParam(addressParam *AddressParam)
func IsMinimallyEncoded ¶
func IsOpCodeDisabled ¶
func MinimallyEncode ¶
Types ¶
type Address ¶
type Address struct {
// contains filtered or unexported fields
}
func AddressFromHash160 ¶
func AddressFromPrivateKey ¶
func AddressFromPublicKey ¶
func AddressFromScriptHash ¶
func AddressFromString ¶
func (*Address) EncodeToPubKeyHash ¶
func (*Address) GetVersion ¶
type AddressParam ¶ added in v0.0.3
type Script ¶
type Script struct { ParsedOpCodes []opcodes.ParsedOpCode // contains filtered or unexported fields }
func NewEmptyScript ¶
func NewEmptyScript() *Script
func NewScriptOps ¶
func NewScriptOps(oldParsedOpCodes []opcodes.ParsedOpCode) *Script
func NewScriptRaw ¶
func (*Script) CheckScriptSigStandard ¶
func (*Script) EncodeSize ¶
func (*Script) ExtractDestinations ¶
func (*Script) GetBadOpCode ¶
func (*Script) GetP2SHSigOpCount ¶
func (*Script) GetSigOpCount ¶
func (*Script) IsCommitment ¶
func (*Script) IsPayToScriptHash ¶
func (*Script) IsPushOnly ¶
func (*Script) IsSpendable ¶
func (*Script) IsStandardScriptPubKey ¶ added in v0.0.3
func (*Script) IsUnspendable ¶
func (*Script) PushMultData ¶
func (*Script) PushOpCode ¶
func (*Script) PushScriptNum ¶
func (*Script) PushSingleData ¶
func (*Script) RemoveOpCodeByIndex ¶
func (*Script) RemoveOpcode ¶
func (*Script) RemoveOpcodeByData ¶
func (*Script) SerializeSize ¶
type ScriptNum ¶
type ScriptNum struct {
Value int64
}
func GetScriptNum ¶
func GetScriptNum(vch []byte, requireMinimal bool, maxNumSize int) (scriptNum *ScriptNum, err error)
GetScriptNum interprets the passed serialized bytes as an encoded integer and returns the result as a script number.
Since the consensus rules dictate that serialized bytes interpreted as ints are only allowed to be in the range determined by a maximum number of bytes, on a per opcode basis, an error will be returned when the provided bytes would result in a number outside of that range. In particular, the range for the vast majority of opcodes dealing with numeric values are limited to 4 bytes and therefore will pass that value to this function resulting in an allowed range of [-2^31 + 1, 2^31 - 1].
The requireMinimal flag causes an error to be returned if additional checks on the encoding determine it is not represented with the smallest possible number of bytes or is the negative 0 encoding, [0x80]. For example, consider the number 127. It could be encoded as [0x7f], [0x7f 0x00], [0x7f 0x00 0x00 ...], etc. All forms except [0x7f] will return an error with requireMinimal enabled.
The scriptNumLen is the maximum number of bytes the encoded value can be before an ErrStackNumberTooBig is returned. This effectively limits the range of allowed values. WARNING: Great care should be taken if passing a value larger than defaultScriptNumLen, which could lead to addition and multiplication overflows.
func NewScriptNum ¶
func (ScriptNum) Bytes ¶
Bytes returns the number serialized as a little endian with a sign bit.
Example encodings:
127 -> [0x7f] -127 -> [0xff] 128 -> [0x80 0x00] -128 -> [0x80 0x80] 129 -> [0x81 0x00] -129 -> [0x81 0x80] 256 -> [0x00 0x01] -256 -> [0x00 0x81] 32767 -> [0xff 0x7f] -32767 -> [0xff 0xff] 32768 -> [0x00 0x80 0x00] -32768 -> [0x00 0x80 0x80]