@@ -45,6 +45,7 @@ func (b *Bridge) DcrmSignTransaction(rawTx interface{}, args *tokens.BuildTxArgs
4545 }
4646 gasPrice , err := b .getGasPrice (args )
4747 if err == nil && args .Extra .EthExtra .GasPrice .Cmp (gasPrice ) < 0 {
48+ log .Info (b .ChainConfig .BlockChain + " DcrmSignTransaction update gas price" , "txid" , args .SwapID , "oldGasPrice" , args .Extra .EthExtra .GasPrice , "newGasPrice" , gasPrice )
4849 args .Extra .EthExtra .GasPrice = gasPrice
4950 tx .SetGasPrice (gasPrice )
5051 }
@@ -72,25 +73,38 @@ func (b *Bridge) DcrmSignTransaction(rawTx interface{}, args *tokens.BuildTxArgs
7273 return nil , "" , errors .New ("wrong signature of keyID " + keyID )
7374 }
7475
75- signedTx , err := tx .WithSignature (signer , signature )
76+ token := b .GetTokenConfig (args .PairID )
77+ signedTx , err := b .signTxWithSignature (tx , signature , common .HexToAddress (token .DcrmAddress ))
7678 if err != nil {
7779 return nil , "" , err
7880 }
81+ txHash = signedTx .Hash ().String ()
82+ log .Info (b .ChainConfig .BlockChain + " DcrmSignTransaction success" , "keyID" , keyID , "txid" , args .SwapID , "txhash" , txHash , "nonce" , signedTx .Nonce ())
83+ return signedTx , txHash , nil
84+ }
7985
80- sender , err := types .Sender (signer , signedTx )
81- if err != nil {
82- return nil , "" , err
83- }
86+ func (b * Bridge ) signTxWithSignature (tx * types.Transaction , signature []byte , signerAddr common.Address ) (* types.Transaction , error ) {
87+ signer := b .Signer
88+ vPos := crypto .SignatureLength - 1
89+ for i := 0 ; i < 2 ; i ++ {
90+ signedTx , err := tx .WithSignature (signer , signature )
91+ if err != nil {
92+ return nil , err
93+ }
8494
85- pairID := args .PairID
86- token := b .GetTokenConfig (pairID )
87- if sender != common .HexToAddress (token .DcrmAddress ) {
88- log .Error ("DcrmSignTransaction verify sender failed" , "have" , sender .String (), "want" , token .DcrmAddress )
89- return nil , "" , errors .New ("wrong sender address" )
95+ sender , err := types .Sender (signer , signedTx )
96+ if err != nil {
97+ return nil , err
98+ }
99+
100+ if sender == signerAddr {
101+ return signedTx , nil
102+ }
103+
104+ signature [vPos ] ^= 0x1 // v can only be 0 or 1
90105 }
91- txHash = signedTx .Hash ().String ()
92- log .Info (b .ChainConfig .BlockChain + " DcrmSignTransaction success" , "keyID" , keyID , "txid" , args .SwapID , "txhash" , txHash , "nonce" , signedTx .Nonce ())
93- return signedTx , txHash , err
106+
107+ return nil , errors .New ("wrong sender address" )
94108}
95109
96110// SignTransaction sign tx with pairID
0 commit comments