MCPcopy Create free account
hub / github.com/chain/Core / P2SPMultiSigProgram

Function P2SPMultiSigProgram

protocol/vmutil/script.go:76–95  ·  view source on GitHub ↗
(pubkeys []ed25519.PublicKey, nrequired int)

Source from the content-addressed store, hash-verified

74}
75
76func P2SPMultiSigProgram(pubkeys []ed25519.PublicKey, nrequired int) ([]byte, error) {
77 err := checkMultiSigParams(int64(nrequired), int64(len(pubkeys)))
78 if err != nil {
79 return nil, err
80 }
81 builder := NewBuilder()
82 // Expected stack: [... NARGS SIG SIG SIG PREDICATE]
83 // Number of sigs must match nrequired.
84 builder.AddOp(vm.OP_DUP).AddOp(vm.OP_TOALTSTACK) // stash a copy of the predicate
85 builder.AddOp(vm.OP_SHA3) // stack is now [... NARGS SIG SIG SIG PREDICATEHASH]
86 for _, p := range pubkeys {
87 builder.AddData(p)
88 }
89 builder.AddInt64(int64(nrequired)) // stack is now [... SIG SIG SIG PREDICATEHASH PUB PUB PUB M]
90 builder.AddInt64(int64(len(pubkeys))) // stack is now [... SIG SIG SIG PREDICATEHASH PUB PUB PUB M N]
91 builder.AddOp(vm.OP_CHECKMULTISIG).AddOp(vm.OP_VERIFY) // stack is now [... NARGS]
92 builder.AddOp(vm.OP_FROMALTSTACK) // stack is now [... NARGS PREDICATE]
93 builder.AddInt64(0).AddOp(vm.OP_CHECKPREDICATE)
94 return builder.Program, nil
95}
96
97func ParseP2SPMultiSigProgram(program []byte) ([]ed25519.PublicKey, int, error) {
98 pops, err := vm.ParseProgram(program)

Callers 1

TestP2SPFunction · 0.85

Calls 5

AddOpMethod · 0.95
AddDataMethod · 0.95
AddInt64Method · 0.95
checkMultiSigParamsFunction · 0.85
NewBuilderFunction · 0.70

Tested by 1

TestP2SPFunction · 0.68