mirror of https://github.com/poanetwork/quorum.git
Merge pull request #3 from jpmorganchase/fix_private_sig
Fix SetPrivate and validation
This commit is contained in:
commit
70448724e8
|
@ -181,7 +181,7 @@ func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool {
|
||||||
if s.Cmp(secp256k1.N) >= 0 {
|
if s.Cmp(secp256k1.N) >= 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if r.Cmp(secp256k1.N) < 0 && (vint == 27 || vint == 28) {
|
if r.Cmp(secp256k1.N) < 0 && (vint == 27 || vint == 28 || vint == 37 || vint == 38) {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -275,7 +275,8 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs
|
||||||
|
|
||||||
var tx *types.Transaction
|
var tx *types.Transaction
|
||||||
data := common.FromHex(args.Data)
|
data := common.FromHex(args.Data)
|
||||||
if len(args.PrivateFor) > 0 {
|
isPrivate := len(args.PrivateFor) > 0
|
||||||
|
if isPrivate {
|
||||||
data, err = private.P.Send(data, args.PrivateFrom, args.PrivateFor)
|
data, err = private.P.Send(data, args.PrivateFrom, args.PrivateFor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
|
@ -286,16 +287,13 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs
|
||||||
} else {
|
} else {
|
||||||
tx = types.NewTransaction(args.Nonce.Uint64(), *args.To, args.Value.BigInt(), args.Gas.BigInt(), args.GasPrice.BigInt(), data)
|
tx = types.NewTransaction(args.Nonce.Uint64(), *args.To, args.Value.BigInt(), args.Gas.BigInt(), args.GasPrice.BigInt(), data)
|
||||||
}
|
}
|
||||||
if len(args.PrivateFor) > 0 {
|
|
||||||
tx.SetPrivate()
|
|
||||||
}
|
|
||||||
|
|
||||||
signature, err := s.am.SignWithPassphrase(args.From, passwd, tx.SigHash().Bytes())
|
signature, err := s.am.SignWithPassphrase(args.From, passwd, tx.SigHash().Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return submitTransaction(ctx, s.b, tx, signature)
|
return submitTransaction(ctx, s.b, tx, signature, isPrivate)
|
||||||
}
|
}
|
||||||
|
|
||||||
// signHash is a helper function that calculates a hash for the given message that can be
|
// signHash is a helper function that calculates a hash for the given message that can be
|
||||||
|
@ -1035,12 +1033,17 @@ func prepareSendTxArgs(ctx context.Context, args SendTxArgs, b Backend) (SendTxA
|
||||||
}
|
}
|
||||||
|
|
||||||
// submitTransaction is a helper function that submits tx to txPool and creates a log entry.
|
// submitTransaction is a helper function that submits tx to txPool and creates a log entry.
|
||||||
func submitTransaction(ctx context.Context, b Backend, tx *types.Transaction, signature []byte) (common.Hash, error) {
|
func submitTransaction(ctx context.Context, b Backend, tx *types.Transaction, signature []byte, isPrivate bool) (common.Hash, error) {
|
||||||
signedTx, err := tx.WithSignature(signature)
|
signedTx, err := tx.WithSignature(signature)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mark private after creating signed copy
|
||||||
|
if isPrivate {
|
||||||
|
signedTx.SetPrivate()
|
||||||
|
}
|
||||||
|
|
||||||
if err := b.SendTx(ctx, signedTx); err != nil {
|
if err := b.SendTx(ctx, signedTx); err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
@ -1075,7 +1078,8 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
|
||||||
|
|
||||||
var tx *types.Transaction
|
var tx *types.Transaction
|
||||||
data := common.FromHex(args.Data)
|
data := common.FromHex(args.Data)
|
||||||
if len(args.PrivateFor) > 0 {
|
isPrivate := len(args.PrivateFor) > 0
|
||||||
|
if isPrivate {
|
||||||
data, err = private.P.Send(data, args.PrivateFrom, args.PrivateFor)
|
data, err = private.P.Send(data, args.PrivateFrom, args.PrivateFor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
|
@ -1086,16 +1090,13 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
|
||||||
} else {
|
} else {
|
||||||
tx = types.NewTransaction(args.Nonce.Uint64(), *args.To, args.Value.BigInt(), args.Gas.BigInt(), args.GasPrice.BigInt(), data)
|
tx = types.NewTransaction(args.Nonce.Uint64(), *args.To, args.Value.BigInt(), args.Gas.BigInt(), args.GasPrice.BigInt(), data)
|
||||||
}
|
}
|
||||||
if len(args.PrivateFor) > 0 {
|
|
||||||
tx.SetPrivate()
|
|
||||||
}
|
|
||||||
|
|
||||||
signature, err := s.b.AccountManager().SignEthereum(args.From, tx.SigHash().Bytes())
|
signature, err := s.b.AccountManager().SignEthereum(args.From, tx.SigHash().Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return submitTransaction(ctx, s.b, tx, signature)
|
return submitTransaction(ctx, s.b, tx, signature, isPrivate)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendRawTransaction will add the signed transaction to the transaction pool.
|
// SendRawTransaction will add the signed transaction to the transaction pool.
|
||||||
|
|
Loading…
Reference in New Issue