diff --git a/tokens/eth/signtx.go b/tokens/eth/signtx.go index 18613f1a..30d15eae 100644 --- a/tokens/eth/signtx.go +++ b/tokens/eth/signtx.go @@ -45,6 +45,7 @@ func (b *Bridge) DcrmSignTransaction(rawTx interface{}, args *tokens.BuildTxArgs } gasPrice, err := b.getGasPrice(args) if err == nil && args.Extra.EthExtra.GasPrice.Cmp(gasPrice) < 0 { + log.Info(b.ChainConfig.BlockChain+" DcrmSignTransaction update gas price", "txid", args.SwapID, "oldGasPrice", args.Extra.EthExtra.GasPrice, "newGasPrice", gasPrice) args.Extra.EthExtra.GasPrice = gasPrice tx.SetGasPrice(gasPrice) } @@ -72,25 +73,38 @@ func (b *Bridge) DcrmSignTransaction(rawTx interface{}, args *tokens.BuildTxArgs return nil, "", errors.New("wrong signature of keyID " + keyID) } - signedTx, err := tx.WithSignature(signer, signature) + token := b.GetTokenConfig(args.PairID) + signedTx, err := b.signTxWithSignature(tx, signature, common.HexToAddress(token.DcrmAddress)) if err != nil { return nil, "", err } + txHash = signedTx.Hash().String() + log.Info(b.ChainConfig.BlockChain+" DcrmSignTransaction success", "keyID", keyID, "txid", args.SwapID, "txhash", txHash, "nonce", signedTx.Nonce()) + return signedTx, txHash, nil +} - sender, err := types.Sender(signer, signedTx) - if err != nil { - return nil, "", err - } +func (b *Bridge) signTxWithSignature(tx *types.Transaction, signature []byte, signerAddr common.Address) (*types.Transaction, error) { + signer := b.Signer + vPos := crypto.SignatureLength - 1 + for i := 0; i < 2; i++ { + signedTx, err := tx.WithSignature(signer, signature) + if err != nil { + return nil, err + } - pairID := args.PairID - token := b.GetTokenConfig(pairID) - if sender != common.HexToAddress(token.DcrmAddress) { - log.Error("DcrmSignTransaction verify sender failed", "have", sender.String(), "want", token.DcrmAddress) - return nil, "", errors.New("wrong sender address") + sender, err := types.Sender(signer, signedTx) + if err != nil { + return nil, err + } + + if sender == signerAddr { + return signedTx, nil + } + + signature[vPos] ^= 0x1 // v can only be 0 or 1 } - txHash = signedTx.Hash().String() - log.Info(b.ChainConfig.BlockChain+" DcrmSignTransaction success", "keyID", keyID, "txid", args.SwapID, "txhash", txHash, "nonce", signedTx.Nonce()) - return signedTx, txHash, err + + return nil, errors.New("wrong sender address") } // SignTransaction sign tx with pairID