Skip to content
Open
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/stretchr/testify v1.7.2
github.com/zeebo/errs v1.2.2
github.com/zeebo/errs/v2 v2.0.3
github.com/zeebo/sudo v1.0.2
github.com/zksync-sdk/zksync-sdk-go v0.0.0-20211119083613-58613b4d3d77
github.com/zksync-sdk/zksync2-go v0.0.0-20230317190602-e188e09f14d1
go.uber.org/zap v1.16.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ github.com/zeebo/errs v1.2.2 h1:5NFypMTuSdoySVTqlNs1dEoU21QVamMQJxW/Fii5O7g=
github.com/zeebo/errs v1.2.2/go.mod h1:sgbWHsvVuTPHcqJJGQ1WhI5KbWlHYz+2+2C/LSEtCw4=
github.com/zeebo/errs/v2 v2.0.3 h1:WwqAmopgot4ZC+CgIveP+H91Nf78NDEGWjtAXen45Hw=
github.com/zeebo/errs/v2 v2.0.3/go.mod h1:OKmvVZt4UqpyJrYFykDKm168ZquJ55pbbIVUICNmLN0=
github.com/zeebo/sudo v1.0.2 h1:6RpQNYeWtd7ycPwYSRgceNdbjodamyyuapNB8mQ1V0M=
github.com/zeebo/sudo v1.0.2/go.mod h1:bO8DB2LXZchv4WMBzo1sCYp24BxAtwa0Lp0XTXU3cU4=
github.com/zksync-sdk/zksync-sdk-go v0.0.0-20211119083613-58613b4d3d77 h1:qcdE1F/TnY4Kck5Uy9SO6avKVcQ53vgFZeuQ4G7jfGk=
github.com/zksync-sdk/zksync-sdk-go v0.0.0-20211119083613-58613b4d3d77/go.mod h1:ZUgHa5wGdUAYfBlO6iEL3UV/IVTiKNI4JuWlLnbBpWM=
github.com/zksync-sdk/zksync2-go v0.0.0-20230317190602-e188e09f14d1 h1:9xUFGuHQgeR0OYoY5e+pdg5DRtyRm/p01dIyyhudj+Y=
Expand Down
31 changes: 29 additions & 2 deletions pkg/eth/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,39 @@ package eth
import (
"context"
"errors"
"reflect"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/zeebo/errs"
"github.com/zeebo/sudo"
"storj.io/crypto-batch-payment/pkg/pipelinedb"
)

func GetTransactionInfo(ctx context.Context, client *ethclient.Client, hash common.Hash) (pipelinedb.TxState, *types.Transaction, *types.Receipt, error) {
tx, pending, err := client.TransactionByHash(ctx, hash)
type rpcTransaction struct {
tx *types.Transaction
BlockNumber *string `json:"blockNumber,omitempty"`
BlockHash *common.Hash `json:"blockHash,omitempty"`
From *common.Address `json:"from,omitempty"`
}

var json *rpcTransaction
var tx *types.Transaction
var pending bool
err := sudo.Sudo(reflect.ValueOf(*client).FieldByName("c")).Interface().(*rpc.Client).CallContext(ctx, &json, "eth_getTransactionByHash", hash)
if err == nil {
if json == nil {
err = ethereum.NotFound
} else {
pending = json.BlockNumber == nil
}
}

//tx, pending, err := client.TransactionByHash(ctx, hash)
switch {
case err == nil:
if pending {
Expand All @@ -25,7 +47,12 @@ func GetTransactionInfo(ctx context.Context, client *ethclient.Client, hash comm
// Failed to issue RPC
return "", nil, nil, errs.Wrap(err)
}
receipt, err := client.TransactionReceipt(ctx, hash)
var receipt *types.Receipt
err = sudo.Sudo(reflect.ValueOf(*client).FieldByName("c")).Interface().(*rpc.Client).CallContext(ctx, &receipt, "eth_getTransactionReceipt", hash)
if err == nil && receipt == nil {
err = ethereum.NotFound
}
// receipt, err := client.TransactionReceipt(ctx, hash)
if err != nil {
if errors.Is(err, ethereum.NotFound) {
return pipelinedb.TxPending, tx, nil, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/payouts/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type AuditStats struct {
func Audit(ctx context.Context, dir string, csvPath string, payerType payer.PayerType, nodeAddress string, chainID int, sink AuditSink, receiptsOut string, receiptsForce bool) (*AuditStats, error) {
var auditor payer.Auditor
switch payerType {
case payer.Eth, payer.Polygon:
case payer.Eth, payer.Polygon, payer.ZkSync2:
client, err := ethclient.Dial(nodeAddress)
if err != nil {
return nil, errs.New("Failed to dial node %q: %v\n", nodeAddress, err)
Expand Down
22 changes: 17 additions & 5 deletions pkg/pipelinedb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"math/big"
"os"
"path/filepath"
"strconv"
"time"

"storj.io/crypto-batch-payment/pkg"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
// "github.com/ethereum/go-ethereum/core/types"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// "github.com/ethereum/go-ethereum/core/types"

"github.com/shopspring/decimal"
"github.com/zeebo/errs"

Expand Down Expand Up @@ -546,6 +547,10 @@ func PayoutGroupFromRow(row *payoutdb.PayoutGroup) (*PayoutGroup, error) {
}, nil
}

type Receipt struct {
GasUsed uint64
}

type Transaction struct {
Hash string
Owner common.Address
Expand All @@ -557,7 +562,7 @@ type Transaction struct {
PayoutGroupID int64
Raw []byte
State TxState
Receipt *types.Receipt
Receipt *Receipt
}

func TransactionsFromRows(rows []*payoutdb.Transaction) ([]*Transaction, error) {
Expand Down Expand Up @@ -596,12 +601,19 @@ func TransactionFromRow(row *payoutdb.Transaction) (*Transaction, error) {

raw := []byte(row.Raw)

var receipt *types.Receipt
var receipt *Receipt
if row.Receipt != nil {
receipt = new(types.Receipt)
if err := json.Unmarshal([]byte(*row.Receipt), receipt); err != nil {
var jsonReceipt struct {
GasUsed string `json:"gasUsed"`
}
if err := json.Unmarshal([]byte(*row.Receipt), &jsonReceipt); err != nil {
return nil, errs.New("unable to convert receipt for transaction pk %d: %v", row.Pk, err)
}
gasUsed, err := strconv.ParseUint(jsonReceipt.GasUsed, 0, 64)
if err != nil {
return nil, errs.New("unable to convert gas used for transaction pk %d: %v", row.Pk, err)
}
receipt = &Receipt{GasUsed: gasUsed}
}

state, ok := TxStateFromString(row.State)
Expand Down