Skip to content

Commit

Permalink
Merge pull request #40 from moonstream-to/customerdb-bytea-address
Browse files Browse the repository at this point in the history
Swithc address format on customer database.
  • Loading branch information
Andrei-Dolgolev authored Jul 15, 2024
2 parents 3d4b015 + bc58a4d commit 282fb88
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 13 deletions.
1 change: 1 addition & 0 deletions blockchain/arbitrum_one/arbitrum_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ func (c *Client) DecodeProtoEntireBlockToLabels(rawData *bytes.Buffer, blocksCac
BlockNumber: e.BlockNumber,
BlockHash: e.BlockHash,
Address: e.Address,
OriginAddress: tx.FromAddress,
TransactionHash: e.TransactionHash,
LabelData: string(labelDataBytes), // Convert JSON byte slice to string
BlockTimestamp: b.Timestamp,
Expand Down
1 change: 1 addition & 0 deletions blockchain/arbitrum_sepolia/arbitrum_sepolia.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ func (c *Client) DecodeProtoEntireBlockToLabels(rawData *bytes.Buffer, blocksCac
BlockNumber: e.BlockNumber,
BlockHash: e.BlockHash,
Address: e.Address,
OriginAddress: tx.FromAddress,
TransactionHash: e.TransactionHash,
LabelData: string(labelDataBytes), // Convert JSON byte slice to string
BlockTimestamp: b.Timestamp,
Expand Down
1 change: 1 addition & 0 deletions blockchain/blockchain.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ func (c *Client) DecodeProtoEntireBlockToLabels(rawData *bytes.Buffer, blocksCac
BlockNumber: e.BlockNumber,
BlockHash: e.BlockHash,
Address: e.Address,
OriginAddress: tx.FromAddress,
TransactionHash: e.TransactionHash,
LabelData: string(labelDataBytes), // Convert JSON byte slice to string
BlockTimestamp: b.Timestamp,
Expand Down
1 change: 1 addition & 0 deletions blockchain/ethereum/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ func (c *Client) DecodeProtoEntireBlockToLabels(rawData *bytes.Buffer, blocksCac
BlockNumber: e.BlockNumber,
BlockHash: e.BlockHash,
Address: e.Address,
OriginAddress: tx.FromAddress,
TransactionHash: e.TransactionHash,
LabelData: string(labelDataBytes), // Convert JSON byte slice to string
BlockTimestamp: b.Timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ func (c *Client) DecodeProtoEntireBlockToLabels(rawData *bytes.Buffer, blocksCac
BlockNumber: e.BlockNumber,
BlockHash: e.BlockHash,
Address: e.Address,
OriginAddress: tx.FromAddress,
TransactionHash: e.TransactionHash,
LabelData: string(labelDataBytes), // Convert JSON byte slice to string
BlockTimestamp: b.Timestamp,
Expand Down
1 change: 1 addition & 0 deletions blockchain/mantle/mantle.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ func (c *Client) DecodeProtoEntireBlockToLabels(rawData *bytes.Buffer, blocksCac
BlockNumber: e.BlockNumber,
BlockHash: e.BlockHash,
Address: e.Address,
OriginAddress: tx.FromAddress,
TransactionHash: e.TransactionHash,
LabelData: string(labelDataBytes), // Convert JSON byte slice to string
BlockTimestamp: b.Timestamp,
Expand Down
1 change: 1 addition & 0 deletions blockchain/mantle_sepolia/mantle_sepolia.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ func (c *Client) DecodeProtoEntireBlockToLabels(rawData *bytes.Buffer, blocksCac
BlockNumber: e.BlockNumber,
BlockHash: e.BlockHash,
Address: e.Address,
OriginAddress: tx.FromAddress,
TransactionHash: e.TransactionHash,
LabelData: string(labelDataBytes), // Convert JSON byte slice to string
BlockTimestamp: b.Timestamp,
Expand Down
1 change: 1 addition & 0 deletions blockchain/polygon/polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ func (c *Client) DecodeProtoEntireBlockToLabels(rawData *bytes.Buffer, blocksCac
BlockNumber: e.BlockNumber,
BlockHash: e.BlockHash,
Address: e.Address,
OriginAddress: tx.FromAddress,
TransactionHash: e.TransactionHash,
LabelData: string(labelDataBytes), // Convert JSON byte slice to string
BlockTimestamp: b.Timestamp,
Expand Down
1 change: 1 addition & 0 deletions blockchain/xai/xai.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ func (c *Client) DecodeProtoEntireBlockToLabels(rawData *bytes.Buffer, blocksCac
BlockNumber: e.BlockNumber,
BlockHash: e.BlockHash,
Address: e.Address,
OriginAddress: tx.FromAddress,
TransactionHash: e.TransactionHash,
LabelData: string(labelDataBytes), // Convert JSON byte slice to string
BlockTimestamp: b.Timestamp,
Expand Down
1 change: 1 addition & 0 deletions blockchain/xai_sepolia/xai_sepolia.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ func (c *Client) DecodeProtoEntireBlockToLabels(rawData *bytes.Buffer, blocksCac
BlockNumber: e.BlockNumber,
BlockHash: e.BlockHash,
Address: e.Address,
OriginAddress: tx.FromAddress,
TransactionHash: e.TransactionHash,
LabelData: string(labelDataBytes), // Convert JSON byte slice to string
BlockTimestamp: b.Timestamp,
Expand Down
61 changes: 49 additions & 12 deletions indexer/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ func (p *PostgreSQLpgx) ReadUpdates(blockchain string, fromBlock uint64, toBlock
}

func (p *PostgreSQLpgx) WriteEvents(blockchain string, events []EventLabel) error {

tableName := LabelsTableName(blockchain)
columns := []string{"id", "label", "transaction_hash", "log_index", "block_number", "block_hash", "block_timestamp", "caller_address", "origin_address", "address", "label_name", "label_type", "label_data"}
var valuesMap = make(map[string]UnnestInsertValueStruct)
Expand Down Expand Up @@ -1068,17 +1069,17 @@ func (p *PostgreSQLpgx) WriteEvents(blockchain string, events []EventLabel) erro
}

valuesMap["caller_address"] = UnnestInsertValueStruct{
Type: "TEXT",
Type: "BYTEA",
Values: make([]interface{}, 0),
}

valuesMap["origin_address"] = UnnestInsertValueStruct{
Type: "TEXT",
Type: "BYTEA",
Values: make([]interface{}, 0),
}

valuesMap["address"] = UnnestInsertValueStruct{
Type: "TEXT",
Type: "BYTEA",
Values: make([]interface{}, 0),
}

Expand All @@ -1101,16 +1102,34 @@ func (p *PostgreSQLpgx) WriteEvents(blockchain string, events []EventLabel) erro

id := uuid.New()

callerAddressBytes, err := decodeAddress(event.CallerAddress)
if err != nil {
fmt.Println("Error decoding caller address:", err, event)
continue
}

originAddressBytes, err := decodeAddress(event.OriginAddress)
if err != nil {
fmt.Println("Error decoding origin address:", err, event)
continue
}

addressBytes, err := decodeAddress(event.Address)
if err != nil {
fmt.Println("Error decoding address:", err, event)
continue
}

updateValues(valuesMap, "id", id)
updateValues(valuesMap, "label", event.Label)
updateValues(valuesMap, "transaction_hash", event.TransactionHash)
updateValues(valuesMap, "log_index", event.LogIndex)
updateValues(valuesMap, "block_number", event.BlockNumber)
updateValues(valuesMap, "block_hash", event.BlockHash)
updateValues(valuesMap, "block_timestamp", event.BlockTimestamp)
updateValues(valuesMap, "caller_address", event.CallerAddress)
updateValues(valuesMap, "origin_address", event.OriginAddress)
updateValues(valuesMap, "address", event.Address)
updateValues(valuesMap, "caller_address", callerAddressBytes)
updateValues(valuesMap, "origin_address", originAddressBytes)
updateValues(valuesMap, "address", addressBytes)
updateValues(valuesMap, "label_name", event.LabelName)
updateValues(valuesMap, "label_type", event.LabelType)
updateValues(valuesMap, "label_data", event.LabelData)
Expand Down Expand Up @@ -1142,7 +1161,7 @@ func (p *PostgreSQLpgx) WriteTransactions(blockchain string, transactions []Tran
}

valuesMap["address"] = UnnestInsertValueStruct{
Type: "TEXT",
Type: "BYTEA",
Values: make([]interface{}, 0),
}

Expand All @@ -1157,7 +1176,7 @@ func (p *PostgreSQLpgx) WriteTransactions(blockchain string, transactions []Tran
}

valuesMap["caller_address"] = UnnestInsertValueStruct{
Type: "TEXT",
Type: "BYTEA",
Values: make([]interface{}, 0),
}

Expand All @@ -1172,7 +1191,7 @@ func (p *PostgreSQLpgx) WriteTransactions(blockchain string, transactions []Tran
}

valuesMap["origin_address"] = UnnestInsertValueStruct{
Type: "TEXT",
Type: "BYTEA",
Values: make([]interface{}, 0),
}

Expand Down Expand Up @@ -1200,14 +1219,32 @@ func (p *PostgreSQLpgx) WriteTransactions(blockchain string, transactions []Tran

id := uuid.New()

addressBytes, err := decodeAddress(transaction.Address)
if err != nil {
fmt.Println("Error decoding address:", err, transaction)
continue
}

callerAddressBytes, err := decodeAddress(transaction.CallerAddress)
if err != nil {
fmt.Println("Error decoding caller address:", err, transaction)
continue
}

originAddressBytes, err := decodeAddress(transaction.OriginAddress)
if err != nil {
fmt.Println("Error decoding origin address:", err, transaction)
continue
}

updateValues(valuesMap, "id", id)
updateValues(valuesMap, "address", transaction.Address)
updateValues(valuesMap, "address", addressBytes)
updateValues(valuesMap, "block_number", transaction.BlockNumber)
updateValues(valuesMap, "block_hash", transaction.BlockHash)
updateValues(valuesMap, "caller_address", transaction.CallerAddress)
updateValues(valuesMap, "caller_address", callerAddressBytes)
updateValues(valuesMap, "label_name", transaction.LabelName)
updateValues(valuesMap, "label_type", transaction.LabelType)
updateValues(valuesMap, "origin_address", transaction.OriginAddress)
updateValues(valuesMap, "origin_address", originAddressBytes)
updateValues(valuesMap, "label", transaction.Label)
updateValues(valuesMap, "transaction_hash", transaction.TransactionHash)
updateValues(valuesMap, "label_data", transaction.LabelData)
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package version

var SeerVersion string = "0.1.11"
var SeerVersion string = "0.1.12"

0 comments on commit 282fb88

Please sign in to comment.