Skip to content

Commit 3c4faf5

Browse files
committed
chore: apply suggestion
1 parent d3e7de8 commit 3c4faf5

File tree

5 files changed

+40
-35
lines changed

5 files changed

+40
-35
lines changed

core/contractsapi/bridge_history.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,19 @@ func (s *Action) GetHistory(ctx context.Context, input types.GetHistoryInput) ([
1818

1919
limit := 20
2020
if input.Limit != nil {
21+
if *input.Limit < 0 {
22+
return nil, errors.New("limit must be non-negative")
23+
}
2124
limit = *input.Limit
25+
if limit > 100 {
26+
limit = 100
27+
}
2228
}
2329
offset := 0
2430
if input.Offset != nil {
31+
if *input.Offset < 0 {
32+
return nil, errors.New("offset must be non-negative")
33+
}
2534
offset = *input.Offset
2635
}
2736

core/types/bridge_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ type BridgeHistory struct {
1818
type GetHistoryInput struct {
1919
BridgeIdentifier string `validate:"required"`
2020
Wallet string `validate:"required"`
21-
Limit *int
22-
Offset *int
21+
Limit *int `validate:"omitempty,min=1"`
22+
Offset *int `validate:"omitempty,min=0"`
2323
}

docs/api-reference.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,23 @@ history, err := client.GetHistory(ctx, types.GetHistoryInput{
10091009
})
10101010
```
10111011

1012+
#### `BridgeHistory` Struct
1013+
1014+
```go
1015+
type BridgeHistory struct {
1016+
Type string `json:"type"` // "deposit" or "withdrawal"
1017+
Amount string `json:"amount"` // NUMERIC(78,0) as string
1018+
FromAddress []byte `json:"from_address"` // Sender address (if available)
1019+
ToAddress []byte `json:"to_address"` // Recipient address
1020+
InternalTxHash []byte `json:"internal_tx_hash"` // Kwil TX hash
1021+
ExternalTxHash []byte `json:"external_tx_hash"` // Ethereum TX hash
1022+
Status string `json:"status"` // "completed", "claimed", "pending_epoch"
1023+
BlockHeight int64 `json:"block_height"` // Kwil block height
1024+
BlockTimestamp int64 `json:"block_timestamp"` // Kwil block timestamp
1025+
ExternalBlockHeight *int64 `json:"external_block_height"` // Ethereum block height
1026+
}
1027+
```
1028+
10121029
### Performance Optimization
10131030

10141031
#### Cache Strategy
@@ -2046,25 +2063,6 @@ type DecodedRow struct {
20462063
}
20472064
```
20482065

2049-
#### `BridgeHistory`
2050-
2051-
Represents a transaction history record from the bridge extension.
2052-
2053-
```go
2054-
type BridgeHistory struct {
2055-
Type string `json:"type"` // "deposit" or "withdrawal"
2056-
Amount string `json:"amount"` // NUMERIC(78,0) as string
2057-
FromAddress []byte `json:"from_address"` // Sender address (if available)
2058-
ToAddress []byte `json:"to_address"` // Recipient address
2059-
InternalTxHash []byte `json:"internal_tx_hash"` // Kwil TX hash
2060-
ExternalTxHash []byte `json:"external_tx_hash"` // Ethereum TX hash
2061-
Status string `json:"status"` // "completed", "claimed", "pending_epoch"
2062-
BlockHeight int64 `json:"block_height"` // Kwil block height
2063-
BlockTimestamp int64 `json:"block_timestamp"` // Kwil block timestamp
2064-
ExternalBlockHeight *int64 `json:"external_block_height"` // Ethereum block height
2065-
}
2066-
```
2067-
20682066
**For attestation results:**
20692067
- `Values[0]`: Unix timestamp as string (e.g., "1704067200")
20702068
- `Values[1]`: 18-decimal fixed-point value as string (e.g., "77.051806494788211665")
16.3 MB
Binary file not shown.

examples/history_example/main.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func main() {
3333
// Use testnet gateway or local node
3434
endpoint := os.Getenv("TN_GATEWAY_URL")
3535
if endpoint == "" {
36-
endpoint = "https://gateway.testnet.truf.network" // Default to local node
36+
endpoint = "https://gateway.testnet.truf.network"
3737
}
3838

3939
client, err := tnclient.NewClient(ctx, endpoint, tnclient.WithSigner(signer))
@@ -77,6 +77,17 @@ func main() {
7777
return
7878
}
7979

80+
// Helper to format byte slices
81+
formatHexShort := func(b []byte) string {
82+
if len(b) == 0 {
83+
return "null"
84+
}
85+
if len(b) > 4 {
86+
return fmt.Sprintf("0x%x...", b[:4])
87+
}
88+
return fmt.Sprintf("0x%x", b)
89+
}
90+
8091
// Use tabwriter for aligned output
8192
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
8293
fmt.Fprintln(w, "TYPE\tAMOUNT\tFROM\tTO\tINTERNAL TX\tEXTERNAL TX\tSTATUS\tBLOCK\tEXT BLOCK\tTIMESTAMP")
@@ -87,19 +98,6 @@ func main() {
8798
tm := time.Unix(rec.BlockTimestamp, 0)
8899
timeStr := tm.Format(time.RFC3339)
89100

90-
// Shorten hashes for display if needed, but printing full for now as per request
91-
// Or shortening to keep table readable? The CLI output truncated them.
92-
// "0x%x..." logic was used before. I will use a helper to optionally shorten.
93-
formatHexShort := func(b []byte) string {
94-
if len(b) == 0 {
95-
return "null"
96-
}
97-
if len(b) > 4 {
98-
return fmt.Sprintf("0x%x...", b[:4])
99-
}
100-
return fmt.Sprintf("0x%x", b)
101-
}
102-
103101
// Handle nullable external block height
104102
extBlock := "null"
105103
if rec.ExternalBlockHeight != nil {

0 commit comments

Comments
 (0)