Example #1
0
func ParseClass(class uint8) string {
	newclass := txscript.ScriptClass(class)

	switch newclass {
	case txscript.NonStandardTy:
		return "nonstandard"

	case txscript.PubKeyTy:
		return "pubkey"

	case txscript.PubKeyHashTy:
		return "pubkeyhash"

	case txscript.ScriptHashTy:
		return "scripthash"

	case txscript.MultiSigTy:
		return "multisig"

	case txscript.NullDataTy:
		return "nulldata"

	default:
		return "invalid"
	}
}
Example #2
0
// TestStringifyClass ensures the script class string returns the expected
// string for each script class.
func TestStringifyClass(t *testing.T) {
	t.Parallel()

	tests := []struct {
		name     string
		class    txscript.ScriptClass
		stringed string
	}{
		{
			name:     "nonstandardty",
			class:    txscript.NonStandardTy,
			stringed: "nonstandard",
		},
		{
			name:     "pubkey",
			class:    txscript.PubKeyTy,
			stringed: "pubkey",
		},
		{
			name:     "pubkeyhash",
			class:    txscript.PubKeyHashTy,
			stringed: "pubkeyhash",
		},
		{
			name:     "scripthash",
			class:    txscript.ScriptHashTy,
			stringed: "scripthash",
		},
		{
			name:     "multisigty",
			class:    txscript.MultiSigTy,
			stringed: "multisig",
		},
		{
			name:     "nulldataty",
			class:    txscript.NullDataTy,
			stringed: "nulldata",
		},
		{
			name:     "broken",
			class:    txscript.ScriptClass(255),
			stringed: "Invalid",
		},
	}

	for _, test := range tests {
		typeString := test.class.String()
		if typeString != test.stringed {
			t.Errorf("%s: got %#q, want %#q", test.name,
				typeString, test.stringed)
		}
	}
}