MCPcopy Create free account
hub / github.com/CPChain/chain / Resend

Method Resend

internal/cpcapi/api.go:1640–1680  ·  view source on GitHub ↗

Resend accepts an existing transaction and a new gas price and limit. It will remove the given transaction from the pool and reinsert it with the new gas price and limit.

(ctx context.Context, sendArgs SendTxArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64)

Source from the content-addressed store, hash-verified

1638// Resend accepts an existing transaction and a new gas price and limit. It will remove
1639// the given transaction from the pool and reinsert it with the new gas price and limit.
1640func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs SendTxArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error) {
1641 if sendArgs.Nonce == nil {
1642 return common.Hash{}, fmt.Errorf("missing transaction nonce in transaction spec")
1643 }
1644 if err := sendArgs.setDefaults(ctx, s.b); err != nil {
1645 return common.Hash{}, err
1646 }
1647 matchTx := sendArgs.toTransaction()
1648 pending, err := s.b.GetPoolTransactions()
1649 if err != nil {
1650 return common.Hash{}, err
1651 }
1652
1653 for _, p := range pending {
1654 var signer types.Signer = types.HomesteadSigner{}
1655 if p.Protected() {
1656 signer = types.NewCep1Signer(p.ChainId())
1657 }
1658 wantSigHash := signer.Hash(matchTx)
1659
1660 if pFrom, err := types.Sender(signer, p); err == nil && pFrom == sendArgs.From && signer.Hash(p) == wantSigHash {
1661 // Match. Re-sign and send the transaction.
1662 if gasPrice != nil && (*big.Int)(gasPrice).Sign() != 0 {
1663 sendArgs.GasPrice = gasPrice
1664 }
1665 if gasLimit != nil && *gasLimit != 0 {
1666 sendArgs.Gas = gasLimit
1667 }
1668 signedTx, err := s.sign(sendArgs.From, sendArgs.toTransaction())
1669 if err != nil {
1670 return common.Hash{}, err
1671 }
1672 if err = s.b.SendTx(ctx, signedTx); err != nil {
1673 return common.Hash{}, err
1674 }
1675 return signedTx.Hash(), nil
1676 }
1677 }
1678
1679 return common.Hash{}, fmt.Errorf("Transaction %#x not found", matchTx.Hash())
1680}
1681
1682// PublicDebugAPI is the collection of Cpchain APIs exposed over the public
1683// debugging endpoint.

Callers

nothing calls this directly

Calls 11

HashMethod · 0.95
signMethod · 0.95
setDefaultsMethod · 0.80
toTransactionMethod · 0.80
GetPoolTransactionsMethod · 0.65
SenderMethod · 0.65
SendTxMethod · 0.65
HashMethod · 0.65
ProtectedMethod · 0.45
ChainIdMethod · 0.45
SignMethod · 0.45

Tested by

no test coverage detected