6 "github.com/vapor/blockchain/txbuilder"
7 "github.com/vapor/crypto/ed25519/chainkd"
8 chainjson "github.com/vapor/encoding/json"
9 "github.com/vapor/errors"
12 // SignFunc is the function passed into Sign that produces
13 // a signature for a given xpub, derivation path, and hash.
14 type SignFunc func(context.Context, chainkd.XPub, [][]byte, [32]byte, string) ([]byte, error)
16 // MaterializeWitnesses takes a filled in Template and "materializes"
17 // each witness component, turning it into a vector of arguments for
18 // the tx's input witness, creating a fully-signed transaction.
19 func materializeWitnesses(txTemplate *Template) error {
20 msg := txTemplate.Transaction
23 return errors.Wrap(txbuilder.ErrMissingRawTx)
26 if len(txTemplate.SigningInstructions) > len(msg.Inputs) {
27 return errors.Wrap(txbuilder.ErrBadInstructionCount)
30 for i, sigInst := range txTemplate.SigningInstructions {
31 if msg.Inputs[sigInst.Position] == nil {
32 return errors.WithDetailf(txbuilder.ErrBadTxInputIdx, "signing instruction %d references missing tx input %d", i, sigInst.Position)
36 for j, wc := range sigInst.WitnessComponents {
37 err := wc.Materialize(&witness)
39 return errors.WithDetailf(err, "error in witness component %d of input %d", j, i)
42 msg.SetInputArguments(sigInst.Position, witness)
48 func signedCount(signs []chainjson.HexBytes) (count int) {
49 for _, sign := range signs {
57 // SignProgress check is all the sign requirement are satisfy
58 func SignProgress(txTemplate *Template) bool {
59 for _, sigInst := range txTemplate.SigningInstructions {
60 for _, wc := range sigInst.WitnessComponents {
61 switch sw := wc.(type) {
62 case *SignatureWitness:
63 if signedCount(sw.Sigs) < sw.Quorum {
66 case *RawTxSigWitness:
67 if signedCount(sw.Sigs) < sw.Quorum {