add a stringer for ScriptClass
This commit is contained in:
parent
b0899204d9
commit
e8321441af
3 changed files with 76 additions and 10 deletions
18
script.go
18
script.go
|
@ -146,6 +146,24 @@ const (
|
|||
NonStandardTy // None of the above.
|
||||
)
|
||||
|
||||
var scriptClassToName = []string{
|
||||
PubKeyTy: "pubkey",
|
||||
PubKeyHashTy: "pubkeyhash",
|
||||
ScriptHashTy: "scripthash",
|
||||
MultiSigTy: "multisig",
|
||||
NonStandardTy: "nonstandard",
|
||||
}
|
||||
|
||||
// String implements the Stringer interface by returning the name of
|
||||
// the enum script class. If the enum is invalid then "Invalid" will be
|
||||
// returned.
|
||||
func (t ScriptClass) String() string {
|
||||
if int(t) > len(scriptClassToName) || int(t) < 0 {
|
||||
return "Invalid"
|
||||
}
|
||||
return scriptClassToName[t]
|
||||
}
|
||||
|
||||
// Script is the virtual machine that executes btcscripts.
|
||||
type Script struct {
|
||||
scripts [][]parsedOpcode
|
||||
|
|
|
@ -2664,3 +2664,50 @@ nexttest:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
var classStringifyTests = []struct{
|
||||
name string
|
||||
scriptclass btcscript.ScriptClass
|
||||
stringed string
|
||||
}{
|
||||
{
|
||||
name: "pubkey",
|
||||
scriptclass: btcscript.PubKeyTy,
|
||||
stringed: "pubkey",
|
||||
},
|
||||
{
|
||||
name: "pubkeyhash",
|
||||
scriptclass: btcscript.PubKeyHashTy,
|
||||
stringed: "pubkeyhash",
|
||||
},
|
||||
{
|
||||
name: "scripthash",
|
||||
scriptclass: btcscript.ScriptHashTy,
|
||||
stringed: "scripthash",
|
||||
},
|
||||
{
|
||||
name: "multisigty",
|
||||
scriptclass: btcscript.MultiSigTy,
|
||||
stringed: "multisig",
|
||||
},
|
||||
{
|
||||
name: "nonstandard",
|
||||
scriptclass: btcscript.NonStandardTy,
|
||||
stringed: "nonstandard",
|
||||
},
|
||||
{
|
||||
name: "broken",
|
||||
scriptclass: btcscript.ScriptClass(255),
|
||||
stringed: "Invalid",
|
||||
},
|
||||
}
|
||||
|
||||
func TestStringifyClass(t *testing.T) {
|
||||
for _, test := range classStringifyTests {
|
||||
typeString := test.scriptclass.String()
|
||||
if typeString != test.stringed {
|
||||
t.Errorf("%s: got \"%s\" expected \"%s\"", test.name,
|
||||
typeString, test.stringed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,24 +84,24 @@ github.com/conformal/btcscript/script.go Script.DisasmPC 100.00% (4/4)
|
|||
github.com/conformal/btcscript/stack.go Stack.PeekBool 100.00% (4/4)
|
||||
github.com/conformal/btcscript/script.go getStack 100.00% (4/4)
|
||||
github.com/conformal/btcscript/script.go IsPayToScriptHash 100.00% (4/4)
|
||||
github.com/conformal/btcscript/address.go ScriptType.String 100.00% (3/3)
|
||||
github.com/conformal/btcscript/script.go setStack 100.00% (3/3)
|
||||
github.com/conformal/btcscript/script.go scriptUInt16 100.00% (3/3)
|
||||
github.com/conformal/btcscript/stack.go fromBool 100.00% (3/3)
|
||||
github.com/conformal/btcscript/script.go scriptUInt8 100.00% (3/3)
|
||||
github.com/conformal/btcscript/script.go setStack 100.00% (3/3)
|
||||
github.com/conformal/btcscript/stack.go fromBool 100.00% (3/3)
|
||||
github.com/conformal/btcscript/script.go scriptUInt16 100.00% (3/3)
|
||||
github.com/conformal/btcscript/script.go scriptUInt32 100.00% (3/3)
|
||||
github.com/conformal/btcscript/opcode.go calcHash 100.00% (2/2)
|
||||
github.com/conformal/btcscript/address.go ScriptType.String 100.00% (3/3)
|
||||
github.com/conformal/btcscript/script.go ScriptClass.String 100.00% (3/3)
|
||||
github.com/conformal/btcscript/stack.go Stack.NipN 100.00% (2/2)
|
||||
github.com/conformal/btcscript/address.go ScriptToAddrHash 100.00% (2/2)
|
||||
github.com/conformal/btcscript/script.go GetSigOpCount 100.00% (2/2)
|
||||
github.com/conformal/btcscript/opcode.go calcHash 100.00% (2/2)
|
||||
github.com/conformal/btcscript/opcode.go opcodeCodeSeparator 100.00% (2/2)
|
||||
github.com/conformal/btcscript/script.go PayToPubKeyHashScript 100.00% (2/2)
|
||||
github.com/conformal/btcscript/opcode.go opcodeDepth 100.00% (2/2)
|
||||
github.com/conformal/btcscript/opcode.go opcodeN 100.00% (2/2)
|
||||
github.com/conformal/btcscript/script.go PayToPubKeyHashScript 100.00% (2/2)
|
||||
github.com/conformal/btcscript/opcode.go opcode1Negate 100.00% (2/2)
|
||||
github.com/conformal/btcscript/stack.go Stack.Depth 100.00% (2/2)
|
||||
github.com/conformal/btcscript/opcode.go opcodeFalse 100.00% (2/2)
|
||||
github.com/conformal/btcscript/stack.go Stack.NipN 100.00% (2/2)
|
||||
github.com/conformal/btcscript/address.go ScriptToAddrHash 100.00% (2/2)
|
||||
github.com/conformal/btcscript/script.go isPubkeyHash 100.00% (1/1)
|
||||
github.com/conformal/btcscript/script.go isScriptHash 100.00% (1/1)
|
||||
github.com/conformal/btcscript/script.go SignatureScript 100.00% (1/1)
|
||||
github.com/conformal/btcscript/script.go parseScript 100.00% (1/1)
|
||||
|
@ -131,6 +131,7 @@ github.com/conformal/btcscript/opcode.go opcode2Drop 100.00% (1/1)
|
|||
github.com/conformal/btcscript/opcode.go opcodeReturn 100.00% (1/1)
|
||||
github.com/conformal/btcscript/opcode.go opcodeNop 100.00% (1/1)
|
||||
github.com/conformal/btcscript/script.go isPubkey 100.00% (1/1)
|
||||
github.com/conformal/btcscript/script.go isPubkeyHash 100.00% (1/1)
|
||||
github.com/conformal/btcscript/opcode.go opcodeOver 100.00% (1/1)
|
||||
github.com/conformal/btcscript/script.go Script.GetStack 100.00% (1/1)
|
||||
github.com/conformal/btcscript/opcode.go calcHash160 100.00% (1/1)
|
||||
|
@ -149,5 +150,5 @@ github.com/conformal/btcscript/script.go Script.Execute 44.44% (8/18)
|
|||
github.com/conformal/btcscript/log.go SetLogWriter 0.00% (0/7)
|
||||
github.com/conformal/btcscript/script.go IsPushOnlyScript 0.00% (0/4)
|
||||
github.com/conformal/btcscript/log.go logClosure.String 0.00% (0/1)
|
||||
github.com/conformal/btcscript --------------------------- 96.58% (989/1024)
|
||||
github.com/conformal/btcscript --------------------------- 96.59% (992/1027)
|
||||
|
||||
|
|
Loading…
Reference in a new issue