draft!!
This commit is contained in:
parent
2341dedfba
commit
233431db8e
|
@ -68,7 +68,7 @@ const (
|
|||
type PendingTransaction struct {
|
||||
Hash common.Hash `json:"hash"`
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
Value bigint.BigInt `json:"value"`
|
||||
Value *hexutil.Big `json:"value"`
|
||||
From common.Address `json:"from"`
|
||||
To common.Address `json:"to"`
|
||||
Data string `json:"data"`
|
||||
|
@ -106,13 +106,13 @@ func (tm *TransactionManager) getAllPendings(chainIDs []uint64) ([]*PendingTrans
|
|||
var transactions []*PendingTransaction
|
||||
for rows.Next() {
|
||||
transaction := &PendingTransaction{
|
||||
Value: bigint.BigInt{Int: new(big.Int)},
|
||||
Value: new(hexutil.Big),
|
||||
GasPrice: bigint.BigInt{Int: new(big.Int)},
|
||||
GasLimit: bigint.BigInt{Int: new(big.Int)},
|
||||
}
|
||||
err := rows.Scan(&transaction.Hash,
|
||||
&transaction.Timestamp,
|
||||
(*bigint.SQLBigIntBytes)(transaction.Value.Int),
|
||||
&transaction.Value,
|
||||
&transaction.From,
|
||||
&transaction.To,
|
||||
&transaction.Data,
|
||||
|
@ -159,13 +159,13 @@ func (tm *TransactionManager) getPendingByAddress(chainIDs []uint64, address com
|
|||
var transactions []*PendingTransaction
|
||||
for rows.Next() {
|
||||
transaction := &PendingTransaction{
|
||||
Value: bigint.BigInt{Int: new(big.Int)},
|
||||
GasPrice: bigint.BigInt{Int: new(big.Int)},
|
||||
Value: new(hexutil.Big),
|
||||
GasPrice: bigint.BigInt{Int: new(big.Int)},
|
||||
GasLimit: bigint.BigInt{Int: new(big.Int)},
|
||||
}
|
||||
err := rows.Scan(&transaction.Hash,
|
||||
&transaction.Timestamp,
|
||||
(*bigint.SQLBigIntBytes)(transaction.Value.Int),
|
||||
&transaction.Value,
|
||||
&transaction.From,
|
||||
&transaction.To,
|
||||
&transaction.Data,
|
||||
|
@ -187,6 +187,7 @@ func (tm *TransactionManager) getPendingByAddress(chainIDs []uint64, address com
|
|||
}
|
||||
|
||||
func (tm *TransactionManager) addPending(transaction PendingTransaction) error {
|
||||
fmt.Println("addPending >>>>>>>>>>>>>>>")
|
||||
insert, err := tm.db.Prepare(`INSERT OR REPLACE INTO pending_transactions
|
||||
(network_id, hash, timestamp, value, from_address, to_address,
|
||||
data, symbol, gas_price, gas_limit, type, additional_data)
|
||||
|
@ -199,7 +200,7 @@ func (tm *TransactionManager) addPending(transaction PendingTransaction) error {
|
|||
transaction.ChainID,
|
||||
transaction.Hash,
|
||||
transaction.Timestamp,
|
||||
(*bigint.SQLBigIntBytes)(transaction.Value.Int),
|
||||
transaction.Value,
|
||||
transaction.From,
|
||||
transaction.To,
|
||||
transaction.Data,
|
||||
|
@ -242,7 +243,8 @@ func (tm *TransactionManager) createMultiTransaction(ctx context.Context, multiT
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result, err := insert.Exec(
|
||||
fmt.Println("multiTransaction.FromAmount.String() = ", multiTransaction.FromAmount.String())
|
||||
result, err := insert.Exec(
|
||||
multiTransaction.FromAddress,
|
||||
multiTransaction.FromAsset,
|
||||
multiTransaction.FromAmount.String(),
|
||||
|
@ -262,6 +264,7 @@ func (tm *TransactionManager) createMultiTransaction(ctx context.Context, multiT
|
|||
|
||||
hashes := make(map[uint64][]types.Hash)
|
||||
for _, tx := range data {
|
||||
fmt.Println("tx.Value() = ", tx.Value(), " >>> ", tx)
|
||||
hash, err := bridges[tx.BridgeName].Send(tx, selectedAccount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -269,13 +272,14 @@ func (tm *TransactionManager) createMultiTransaction(ctx context.Context, multiT
|
|||
err = tm.addPending(PendingTransaction{
|
||||
Hash: common.Hash(hash),
|
||||
Timestamp: uint64(time.Now().Unix()),
|
||||
Value: bigint.BigInt{tx.Value()},
|
||||
Value: multiTransaction.FromAmount,
|
||||
From: common.Address(tx.From()),
|
||||
To: common.Address(tx.To()),
|
||||
Data: tx.Data().String(),
|
||||
Type: WalletTransfer,
|
||||
ChainID: tx.ChainID,
|
||||
MultiTransactionID: multiTransactionID,
|
||||
Symbol: multiTransaction.FromAsset,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -5,11 +5,11 @@ import (
|
|||
"math/big"
|
||||
"strings"
|
||||
"time"
|
||||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/status-im/status-go/services/wallet/async"
|
||||
"github.com/status-im/status-go/services/wallet/chain"
|
||||
)
|
||||
|
@ -67,14 +67,14 @@ func (c *ethHistoricalCommand) Run(ctx context.Context) (err error) {
|
|||
c.foundHeaders = headers
|
||||
c.resultingFrom = from
|
||||
|
||||
log.Info("eth historical downloader finished successfully", "address", c.address, "from", from, "to", c.to, "total blocks", len(headers), "time", time.Since(start))
|
||||
fmt.Println("eth historical downloader finished successfully", "address", c.address, "from", from, "to", c.to, "total blocks", len(headers), "time", time.Since(start))
|
||||
|
||||
//err = c.db.ProcessBlocks(c.address, from, c.to, headers, ethTransfer)
|
||||
if err != nil {
|
||||
log.Error("failed to save found blocks with transfers", "error", err)
|
||||
fmt.Println("failed to save found blocks with transfers", "error", err)
|
||||
return err
|
||||
}
|
||||
log.Debug("eth transfers were persisted. command is closed")
|
||||
fmt.Println("eth transfers were persisted. command is closed")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -117,14 +117,14 @@ func (c *erc20HistoricalCommand) Run(ctx context.Context) (err error) {
|
|||
c.db, c.chainClient, c.address,
|
||||
c.erc20, getErc20BatchSize(c.chainClient.ChainID), c.to, c.from)
|
||||
if err != nil {
|
||||
log.Error("failed to setup historical downloader for erc20")
|
||||
fmt.Println("failed to setup historical downloader for erc20")
|
||||
return err
|
||||
}
|
||||
}
|
||||
for !c.iterator.Finished() {
|
||||
headers, _, _, err := c.iterator.Next(ctx)
|
||||
if err != nil {
|
||||
log.Error("failed to get next batch", "error", err)
|
||||
fmt.Println("failed to get next batch", "error", err)
|
||||
return err
|
||||
}
|
||||
c.foundHeaders = append(c.foundHeaders, headers...)
|
||||
|
@ -132,11 +132,11 @@ func (c *erc20HistoricalCommand) Run(ctx context.Context) (err error) {
|
|||
/*err = c.db.ProcessBlocks(c.address, from, to, headers, erc20Transfer)
|
||||
if err != nil {
|
||||
c.iterator.Revert()
|
||||
log.Error("failed to save downloaded erc20 blocks with transfers", "error", err)
|
||||
fmt.Println("failed to save downloaded erc20 blocks with transfers", "error", err)
|
||||
return err
|
||||
}*/
|
||||
}
|
||||
log.Info("wallet historical downloader for erc20 transfers finished", "in", time.Since(start))
|
||||
fmt.Println("wallet historical downloader for erc20 transfers finished", "in", time.Since(start))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ func (c *controlCommand) LoadTransfers(ctx context.Context, downloader *ETHDownl
|
|||
}
|
||||
|
||||
func (c *controlCommand) Run(parent context.Context) error {
|
||||
log.Info("start control command")
|
||||
fmt.Println("start control command")
|
||||
ctx, cancel := context.WithTimeout(parent, 3*time.Second)
|
||||
head, err := c.chainClient.HeaderByNumber(ctx, nil)
|
||||
cancel()
|
||||
|
@ -177,10 +177,10 @@ func (c *controlCommand) Run(parent context.Context) error {
|
|||
Accounts: c.accounts,
|
||||
})
|
||||
|
||||
log.Info("current head is", "block number", head.Number)
|
||||
fmt.Println("current head is", "block number", head.Number)
|
||||
lastKnownEthBlocks, accountsWithoutHistory, err := c.block.GetLastKnownBlockByAddresses(c.chainClient.ChainID, c.accounts)
|
||||
if err != nil {
|
||||
log.Error("failed to load last head from database", "error", err)
|
||||
fmt.Println("failed to load last head from database", "error", err)
|
||||
if c.NewError(err) {
|
||||
return nil
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ func (c *controlCommand) Run(parent context.Context) error {
|
|||
BlockNumber: target,
|
||||
})
|
||||
|
||||
log.Info("end control command")
|
||||
fmt.Println("end control command")
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -293,9 +293,9 @@ func nonArchivalNodeError(err error) bool {
|
|||
|
||||
func (c *controlCommand) NewError(err error) bool {
|
||||
c.errorsCount++
|
||||
log.Error("controlCommand error", "error", err, "counter", c.errorsCount)
|
||||
fmt.Println("controlCommand error", "error", err, "counter", c.errorsCount)
|
||||
if nonArchivalNodeError(err) {
|
||||
log.Info("Non archival node detected")
|
||||
fmt.Println("Non archival node detected")
|
||||
c.nonArchivalRPCNode = true
|
||||
c.feed.Send(Event{
|
||||
Type: EventNonArchivalNodeDetected,
|
||||
|
@ -337,18 +337,18 @@ func (c *transfersCommand) Command() async.Command {
|
|||
func (c *transfersCommand) Run(ctx context.Context) (err error) {
|
||||
allTransfers, err := getTransfersByBlocks(ctx, c.db, c.eth, c.address, []*big.Int{c.block})
|
||||
if err != nil {
|
||||
log.Info("getTransfersByBlocks error", "error", err)
|
||||
fmt.Println("getTransfersByBlocks error", "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.db.SaveTranfers(c.chainClient.ChainID, c.address, allTransfers, []*big.Int{c.block})
|
||||
if err != nil {
|
||||
log.Error("SaveTranfers error", "error", err)
|
||||
fmt.Println("SaveTranfers error", "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
c.fetchedTransfers = allTransfers
|
||||
log.Debug("transfers loaded", "address", c.address, "len", len(allTransfers))
|
||||
fmt.Println("transfers loaded", "address", c.address, "len", len(allTransfers))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -409,7 +409,7 @@ func (c *findAndCheckBlockRangeCommand) Command() async.Command {
|
|||
}
|
||||
|
||||
func (c *findAndCheckBlockRangeCommand) Run(parent context.Context) (err error) {
|
||||
log.Debug("start findAndCHeckBlockRangeCommand")
|
||||
fmt.Println("start findAndCHeckBlockRangeCommand")
|
||||
newFromByAddress, ethHeadersByAddress, err := c.fastIndex(parent, c.balanceCache, c.fromByAddress, c.toByAddress)
|
||||
if err != nil {
|
||||
c.error = err
|
||||
|
@ -460,7 +460,7 @@ func (c *findAndCheckBlockRangeCommand) Run(parent context.Context) (err error)
|
|||
}
|
||||
|
||||
lastBlockNumber := c.toByAddress[address]
|
||||
log.Debug("saving headers", "len", len(uniqHeaders), "lastBlockNumber", lastBlockNumber, "balance", c.balanceCache.ReadCachedBalance(address, lastBlockNumber), "nonce", c.balanceCache.ReadCachedNonce(address, lastBlockNumber))
|
||||
fmt.Println("saving headers", "len", len(uniqHeaders), "lastBlockNumber", lastBlockNumber, "balance", c.balanceCache.ReadCachedBalance(address, lastBlockNumber), "nonce", c.balanceCache.ReadCachedNonce(address, lastBlockNumber))
|
||||
to := &LastKnownBlock{
|
||||
Number: lastBlockNumber,
|
||||
Balance: c.balanceCache.ReadCachedBalance(address, lastBlockNumber),
|
||||
|
@ -517,7 +517,7 @@ func (c *findAndCheckBlockRangeCommand) fastIndex(ctx context.Context, bCache *b
|
|||
resultingFromByAddress[command.address] = command.resultingFrom
|
||||
headers[command.address] = command.foundHeaders
|
||||
}
|
||||
log.Info("fast indexer finished", "in", time.Since(start))
|
||||
fmt.Println("fast indexer finished", "in", time.Since(start))
|
||||
return resultingFromByAddress, headers, nil
|
||||
}
|
||||
}
|
||||
|
@ -551,7 +551,7 @@ func (c *findAndCheckBlockRangeCommand) fastIndexErc20(ctx context.Context, from
|
|||
for _, command := range commands {
|
||||
headres[command.address] = command.foundHeaders
|
||||
}
|
||||
log.Info("fast indexer Erc20 finished", "in", time.Since(start))
|
||||
fmt.Println("fast indexer Erc20 finished", "in", time.Since(start))
|
||||
return headres, nil
|
||||
}
|
||||
}
|
||||
|
@ -603,7 +603,7 @@ func loadTransfers(ctx context.Context, accounts []common.Address, block *Block,
|
|||
transfersByAddress[command.address] = append(transfers, transfer)
|
||||
}
|
||||
}
|
||||
log.Info("loadTransfers finished", "in", time.Since(start))
|
||||
fmt.Println("loadTransfers finished", "in", time.Since(start))
|
||||
return transfersByAddress, nil
|
||||
}
|
||||
}
|
||||
|
@ -631,7 +631,7 @@ func findFirstRange(c context.Context, account common.Address, initialTo *big.In
|
|||
}
|
||||
|
||||
firstNonce, err := client.NonceAt(c, account, to)
|
||||
log.Info("find range with 20 <= len(tx) <= 25", "account", account, "firstNonce", firstNonce, "from", from, "to", to)
|
||||
fmt.Println("find range with 20 <= len(tx) <= 25", "account", account, "firstNonce", firstNonce, "from", from, "to", to)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -664,15 +664,15 @@ func findFirstRange(c context.Context, account common.Address, initialTo *big.In
|
|||
}
|
||||
nonceDiff = firstNonce - fromNonce
|
||||
|
||||
log.Info("next nonce", "from", from, "n", fromNonce, "diff", firstNonce-fromNonce)
|
||||
fmt.Println("next nonce", "from", from, "n", fromNonce, "diff", firstNonce-fromNonce)
|
||||
|
||||
if goal <= nonceDiff && nonceDiff <= (goal+5) {
|
||||
log.Info("range found", "account", account, "from", from, "to", to)
|
||||
fmt.Println("range found", "account", account, "from", from, "to", to)
|
||||
return from, nil
|
||||
}
|
||||
}
|
||||
|
||||
log.Info("range found", "account", account, "from", from, "to", to)
|
||||
fmt.Println("range found", "account", account, "from", from, "to", to)
|
||||
|
||||
return from, nil
|
||||
}
|
||||
|
@ -700,7 +700,7 @@ func getTransfersByBlocks(ctx context.Context, db *Database, downloader *ETHDown
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Debug("loadTransfers", "block", block, "new transfers", len(transfers))
|
||||
fmt.Println("loadTransfers", "block", block, "new transfers", len(transfers))
|
||||
if len(transfers) > 0 {
|
||||
allTransfers = append(allTransfers, transfers...)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ const (
|
|||
// EventFetchingHistoryError emitted when fetching of tx history failed
|
||||
EventFetchingHistoryError EventType = "fetching-history-error"
|
||||
// EventNonArchivalNodeDetected emitted when a connection to a non archival node is detected
|
||||
EventNonArchivalNodeDetected EventType = "non-archival-node-detected"
|
||||
EventNonArchivalNodeDetected EventType = "non-archival-node-detected"
|
||||
)
|
||||
|
||||
// Event is a type for transfer events.
|
||||
|
|
Loading…
Reference in New Issue