X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=blockchain%2Ftxbuilder%2Fsignature_witness.go;h=3997bf9c87e92526b281e4d97ac70c80c9948019;hb=a2524758ec0a53776f22e974ee9635af9c164300;hp=fee482297a9cb3779dbebdea0db64f28d70887a9;hpb=9c14fe5e1ef600420ae96fe7107df8b85ebe2ded;p=bytom%2Fbytom.git diff --git a/blockchain/txbuilder/signature_witness.go b/blockchain/txbuilder/signature_witness.go index fee48229..3997bf9c 100644 --- a/blockchain/txbuilder/signature_witness.go +++ b/blockchain/txbuilder/signature_witness.go @@ -1,3 +1,5 @@ +// +build !gm + package txbuilder import ( @@ -6,11 +8,11 @@ import ( log "github.com/sirupsen/logrus" - "github.com/bytom/crypto/ed25519/chainkd" - "github.com/bytom/crypto/sha3pool" - chainjson "github.com/bytom/encoding/json" - "github.com/bytom/errors" - "github.com/bytom/protocol/vm" + "github.com/bytom/bytom/crypto/ed25519/chainkd" + "github.com/bytom/bytom/crypto/sha3pool" + chainjson "github.com/bytom/bytom/encoding/json" + "github.com/bytom/bytom/errors" + "github.com/bytom/bytom/protocol/vm" ) type ( @@ -42,16 +44,15 @@ type ( var ErrEmptyProgram = errors.New("empty signature program") // Sign populates sw.Sigs with as many signatures of the predicate in -// sw.Program as it can from the overlapping set of keys in sw.Keys -// and xpubs. +// sw.Program as it can from the overlapping set of keys in sw.Keys. // // If sw.Program is empty, it is populated with an _inferred_ predicate: // a program committing to aspects of the current // transaction. Specifically, the program commits to: // - the mintime and maxtime of the transaction (if non-zero) -// - the outputID and (if non-empty) reference data of the current input -// - the assetID, amount, control program, and (if non-empty) reference data of each output. -func (sw *SignatureWitness) sign(ctx context.Context, tpl *Template, index uint32, xpubs []chainkd.XPub, auth string, signFn SignFunc) error { +// - the outputID of the current input +// - the assetID, amount, control program of each output. +func (sw *SignatureWitness) sign(ctx context.Context, tpl *Template, index uint32, auth string, signFn SignFunc) error { // Compute the predicate to sign. This is either a // txsighash program if tpl.AllowAdditional is false (i.e., the tx is complete // and no further changes are allowed) or a program enforcing @@ -81,26 +82,21 @@ func (sw *SignatureWitness) sign(ctx context.Context, tpl *Template, index uint3 // Already have a signature for this key continue } - var found bool - for _, xpub := range xpubs { - if keyID.XPub == xpub { - found = true - break - } - } - if xpubs != nil && !found { - continue - } - path := make([]([]byte), len(keyID.DerivationPath)) + path := make([][]byte, len(keyID.DerivationPath)) for i, p := range keyID.DerivationPath { path[i] = p } sigBytes, err := signFn(ctx, keyID.XPub, path, h, auth) if err != nil { - log.WithField("err", err).Warningf("computing signature %d", i) + log.WithFields(log.Fields{"module": logModule, "err": err}).Warningf("computing signature %d", i) continue } + + // This break is ordered to avoid signing transaction successfully only once for a multiple-sign account + // that consist of different keys by the same password. Exit immediately when the signature is success, + // it means that only one signature will be successful in the loop for this multiple-sign account. sw.Sigs[i] = sigBytes + break } return nil } @@ -110,7 +106,7 @@ func (sw SignatureWitness) materialize(args *[][]byte) error { // assumes that everything already in the arg list before this call // to Materialize is input to the signature program, so N is // len(*args). - *args = append(*args, vm.Int64Bytes(int64(len(*args)))) + *args = append(*args, vm.Uint64Bytes(uint64(len(*args)))) var nsigs int for i := 0; i < len(sw.Sigs) && nsigs < sw.Quorum; i++ {