feat: add timestamp and txType to event payload

* closes #39
This commit is contained in:
Mohamed Sohail 2023-04-24 07:25:25 +00:00
parent bf029ebabf
commit a291512d95
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
5 changed files with 25 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"github.com/celo-org/celo-blockchain/common"
"github.com/celo-org/celo-blockchain/common/hexutil"
"github.com/grassrootseconomics/celoutils"
"github.com/grassrootseconomics/cic-chain-events/internal/pub"
"github.com/grassrootseconomics/cic-chain-events/pkg/fetch"
@ -53,9 +54,11 @@ func (f *GasFilter) Execute(_ context.Context, transaction *fetch.Transaction) (
giveToEvent := &pub.MinimalTxInfo{
Block: transaction.Block.Number,
ContractAddress: celoutils.ChecksumAddress(transaction.To.Address),
Timestamp: hexutil.MustDecodeUint64(transaction.Block.Timestamp),
To: address.Hex(),
TxHash: transaction.Hash,
TxIndex: transaction.Index,
TXType: "gas",
}
if transaction.Status == 1 {

View File

@ -4,6 +4,7 @@ import (
"context"
"github.com/celo-org/celo-blockchain/common"
"github.com/celo-org/celo-blockchain/common/hexutil"
"github.com/grassrootseconomics/celoutils"
"github.com/grassrootseconomics/cic-chain-events/internal/pub"
"github.com/grassrootseconomics/cic-chain-events/pkg/fetch"
@ -21,25 +22,25 @@ var (
type (
RegisterFilterOpts struct {
Logg logf.Logger
Pub *pub.Pub
Logg logf.Logger
Pub *pub.Pub
}
RegisterFilter struct {
logg logf.Logger
pub *pub.Pub
logg logf.Logger
pub *pub.Pub
}
)
func NewRegisterFilter(o RegisterFilterOpts) Filter {
return &RegisterFilter{
logg: o.Logg,
pub: o.Pub,
logg: o.Logg,
pub: o.Pub,
}
}
func (f *RegisterFilter) Execute(_ context.Context, transaction *fetch.Transaction) (bool, error) {
if len(transaction.InputData) < 10 {
if len(transaction.InputData) < 10 {
return true, nil
}
@ -53,9 +54,11 @@ func (f *RegisterFilter) Execute(_ context.Context, transaction *fetch.Transacti
addEvent := &pub.MinimalTxInfo{
Block: transaction.Block.Number,
ContractAddress: celoutils.ChecksumAddress(transaction.To.Address),
Timestamp: hexutil.MustDecodeUint64(transaction.Block.Timestamp),
To: address.Hex(),
TxHash: transaction.Hash,
TxIndex: transaction.Index,
TXType: "register",
}
if transaction.Status == 1 {

View File

@ -6,6 +6,7 @@ import (
"sync"
"github.com/celo-org/celo-blockchain/common"
"github.com/celo-org/celo-blockchain/common/hexutil"
"github.com/grassrootseconomics/celoutils"
"github.com/grassrootseconomics/cic-chain-events/internal/pub"
"github.com/grassrootseconomics/cic-chain-events/pkg/fetch"
@ -60,9 +61,11 @@ func (f *TokenIndexFilter) Execute(_ context.Context, transaction *fetch.Transac
addEvent := &pub.MinimalTxInfo{
Block: transaction.Block.Number,
ContractAddress: celoutils.ChecksumAddress(transaction.To.Address),
Timestamp: hexutil.MustDecodeUint64(transaction.Block.Timestamp),
To: address.Hex(),
TxHash: transaction.Hash,
TxIndex: transaction.Index,
TXType: "tokenAdd",
}
if transaction.Status == 1 {

View File

@ -5,6 +5,7 @@ import (
"math/big"
"github.com/celo-org/celo-blockchain/common"
"github.com/celo-org/celo-blockchain/common/hexutil"
"github.com/grassrootseconomics/celoutils"
"github.com/grassrootseconomics/cic-chain-events/internal/pub"
"github.com/grassrootseconomics/cic-chain-events/pkg/fetch"
@ -60,10 +61,12 @@ func (f *TransferFilter) Execute(_ context.Context, transaction *fetch.Transacti
transferEvent := &pub.MinimalTxInfo{
Block: transaction.Block.Number,
From: celoutils.ChecksumAddress(transaction.From.Address),
Timestamp: hexutil.MustDecodeUint64(transaction.Block.Timestamp),
To: to.Hex(),
ContractAddress: celoutils.ChecksumAddress(transaction.To.Address),
TxHash: transaction.Hash,
TxIndex: transaction.Index,
TXType: "transfer",
Value: value.Uint64(),
}
@ -94,10 +97,12 @@ func (f *TransferFilter) Execute(_ context.Context, transaction *fetch.Transacti
transferEvent := &pub.MinimalTxInfo{
Block: transaction.Block.Number,
From: from.Hex(),
Timestamp: hexutil.MustDecodeUint64(transaction.Block.Timestamp),
To: to.Hex(),
ContractAddress: celoutils.ChecksumAddress(transaction.To.Address),
TxHash: transaction.Hash,
TxIndex: transaction.Index,
TXType: "transferFrom",
Value: value.Uint64(),
}
@ -127,10 +132,12 @@ func (f *TransferFilter) Execute(_ context.Context, transaction *fetch.Transacti
transferEvent := &pub.MinimalTxInfo{
Block: transaction.Block.Number,
From: celoutils.ChecksumAddress(transaction.From.Address),
Timestamp: hexutil.MustDecodeUint64(transaction.Block.Timestamp),
To: to.Hex(),
ContractAddress: celoutils.ChecksumAddress(transaction.To.Address),
TxHash: transaction.Hash,
TxIndex: transaction.Index,
TXType: "mintTo",
Value: value.Uint64(),
}

View File

@ -31,8 +31,10 @@ type (
To string `json:"to"`
ContractAddress string `json:"contractAddress"`
Success bool `json:"success"`
Timestamp uint64 `json:"timestamp"`
TxHash string `json:"transactionHash"`
TxIndex uint `json:"transactionIndex"`
TXType string `json:"txType"`
Value uint64 `json:"value"`
}
)