Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SetPrivate and validation #3

Merged
merged 1 commit into from
Nov 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool {
if s.Cmp(secp256k1.N) >= 0 {
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
} else {
return false
Expand Down
23 changes: 12 additions & 11 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs

var tx *types.Transaction
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)
if err != nil {
return common.Hash{}, err
Expand All @@ -286,16 +287,13 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs
} else {
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())
if err != nil {
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
Expand Down Expand Up @@ -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.
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)
if err != nil {
return common.Hash{}, err
}

// mark private after creating signed copy
if isPrivate {
signedTx.SetPrivate()
}

if err := b.SendTx(ctx, signedTx); err != nil {
return common.Hash{}, err
}
Expand Down Expand Up @@ -1075,7 +1078,8 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen

var tx *types.Transaction
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)
if err != nil {
return common.Hash{}, err
Expand All @@ -1086,16 +1090,13 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
} else {
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())
if err != nil {
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.
Expand Down