Add support for nulldata standard scripts.
This commit adds the new standard script type for empty, but data carrying and provably prunable transaction scripts. Closes #2. ok @owainga
This commit is contained in:
parent
c33bd15df2
commit
cfc2a4cc76
1 changed files with 25 additions and 4 deletions
29
script.go
29
script.go
|
@ -139,19 +139,21 @@ type ScriptClass byte
|
||||||
|
|
||||||
// Classes of script payment known about in the blockchain.
|
// Classes of script payment known about in the blockchain.
|
||||||
const (
|
const (
|
||||||
PubKeyTy ScriptClass = iota // Pay pubkey.
|
NonStandardTy ScriptClass = iota // None of the recognized forms.
|
||||||
|
PubKeyTy // Pay pubkey.
|
||||||
PubKeyHashTy // Pay pubkey hash.
|
PubKeyHashTy // Pay pubkey hash.
|
||||||
ScriptHashTy // Pay to script hash.
|
ScriptHashTy // Pay to script hash.
|
||||||
MultiSigTy // Multi signature.
|
MultiSigTy // Multi signature.
|
||||||
NonStandardTy // None of the above.
|
NullDataTy // Empty data-only (provably prunable).
|
||||||
)
|
)
|
||||||
|
|
||||||
var scriptClassToName = []string{
|
var scriptClassToName = []string{
|
||||||
|
NonStandardTy: "nonstandard",
|
||||||
PubKeyTy: "pubkey",
|
PubKeyTy: "pubkey",
|
||||||
PubKeyHashTy: "pubkeyhash",
|
PubKeyHashTy: "pubkeyhash",
|
||||||
ScriptHashTy: "scripthash",
|
ScriptHashTy: "scripthash",
|
||||||
MultiSigTy: "multisig",
|
MultiSigTy: "multisig",
|
||||||
NonStandardTy: "nonstandard",
|
NullDataTy: "nulldata",
|
||||||
}
|
}
|
||||||
|
|
||||||
// String implements the Stringer interface by returning the name of
|
// String implements the Stringer interface by returning the name of
|
||||||
|
@ -251,6 +253,22 @@ func isMultiSig(pops []parsedOpcode) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isNullData returns true if the passed script is a null data transaction,
|
||||||
|
// false otherwise.
|
||||||
|
func isNullData(pops []parsedOpcode) bool {
|
||||||
|
// A nulldata transaction is either a single OP_RETURN or an
|
||||||
|
// OP_RETURN SMALLDATA (where SMALLDATA is a push data up to 80 bytes).
|
||||||
|
l := len(pops)
|
||||||
|
if l == 1 && pops[0].opcode.value == OP_RETURN {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return l == 2 &&
|
||||||
|
pops[0].opcode.value == OP_RETURN &&
|
||||||
|
pops[1].opcode.value <= OP_PUSHDATA4 &&
|
||||||
|
len(pops[1].data) <= 80
|
||||||
|
}
|
||||||
|
|
||||||
// isPushOnly returns true if the script only pushes data, false otherwise.
|
// isPushOnly returns true if the script only pushes data, false otherwise.
|
||||||
func isPushOnly(pops []parsedOpcode) bool {
|
func isPushOnly(pops []parsedOpcode) bool {
|
||||||
// technically we cheat here, we don't look at opcodes
|
// technically we cheat here, we don't look at opcodes
|
||||||
|
@ -297,6 +315,8 @@ func typeOfScript(pops []parsedOpcode) ScriptClass {
|
||||||
return ScriptHashTy
|
return ScriptHashTy
|
||||||
} else if isMultiSig(pops) {
|
} else if isMultiSig(pops) {
|
||||||
return MultiSigTy
|
return MultiSigTy
|
||||||
|
} else if isNullData(pops) {
|
||||||
|
return NullDataTy
|
||||||
}
|
}
|
||||||
return NonStandardTy
|
return NonStandardTy
|
||||||
|
|
||||||
|
@ -1070,10 +1090,11 @@ func expectedInputs(pops []parsedOpcode, class ScriptClass) int {
|
||||||
// expected. typoeOfScript already checked this so that we know
|
// expected. typoeOfScript already checked this so that we know
|
||||||
// it'll be one of OP_1 - OP_16.
|
// it'll be one of OP_1 - OP_16.
|
||||||
return int(pops[0].opcode.value - (OP_1 - 1))
|
return int(pops[0].opcode.value - (OP_1 - 1))
|
||||||
|
case NullDataTy:
|
||||||
|
fallthrough
|
||||||
default:
|
default:
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ScriptInfo struct {
|
type ScriptInfo struct {
|
||||||
|
|
Loading…
Add table
Reference in a new issue