Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swithc address format on customer database. #40

Merged
merged 3 commits into from
Jul 15, 2024
Merged
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 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"
Loading