Skip to content

Commit aacd7ed

Browse files
committed
Fix POWOperation nonce type to support large values beyond int64 range
- Change POWOperation.Nonce from *Int to *UInt64 to match Steem protocol (nonce is uint64_t in C++ code) - Add test cases to verify large nonce values can be parsed correctly - Fixes unmarshal error for block 64500 where nonce value "11115213149964598312" exceeds int64 maximum This resolves the issue where parsing operations in block 64500 failed with: "strconv.ParseInt: parsing '11115213149964598312': value out of range"
1 parent d96aed1 commit aacd7ed

2 files changed

Lines changed: 88 additions & 1 deletion

File tree

protocol/operations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func formatAssetFromObject(amount, nai string, precision uint8) string {
212212
type POWOperation struct {
213213
WorkerAccount string `json:"worker_account"`
214214
BlockID string `json:"block_id"`
215-
Nonce *Int `json:"nonce"`
215+
Nonce *UInt64 `json:"nonce"`
216216
Work *POW `json:"work"`
217217
Props *ChainProperties `json:"props"`
218218
}

protocol/operations_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,3 +618,90 @@ func TestChainProperties_UnmarshalJSON_POWOperation(t *testing.T) {
618618
t.Errorf("expected AccountCreationFee to be '100.000 STEEM', got '%s'", op.Props.AccountCreationFee)
619619
}
620620
}
621+
622+
func TestPOWOperation_UnmarshalJSON_LargeNonce(t *testing.T) {
623+
// Test that large nonce values (beyond int64 range) can be parsed correctly
624+
// This is based on the actual data from block 64500
625+
jsonData := `{
626+
"worker_account": "sminer47",
627+
"block_id": "0000fbf357840bfa4e52b569a0498edb20efbe0c",
628+
"nonce": "11115213149964598312",
629+
"work": {
630+
"worker": "STM6tC4qRjUPKmkqkug5DvSgkeND5DHhnfr3XTgpp4b4nejMEwn9k",
631+
"input": "d29c469c89252a297cb22c949268593c7c6dcf012c836ce004bf04f7922d1405",
632+
"signature": "1fcc715d38c35fcb35dcce0056e770419d5f327c64b2583ba2e8cc7951de6fb0d562b7d6258d5fff41725edd987b2b91cb7c42c9a24eac84c4a393930ec318f3e2",
633+
"work": "000000054cbe98830fff5628cb2f9f0464812cf117c55e30e1e0f9d3ac7ef5c2"
634+
},
635+
"props": {
636+
"account_creation_fee": "100.000 STEEM",
637+
"maximum_block_size": 131072,
638+
"sbd_interest_rate": 1000
639+
}
640+
}`
641+
642+
var op POWOperation
643+
if err := json.Unmarshal([]byte(jsonData), &op); err != nil {
644+
t.Fatalf("Failed to unmarshal POWOperation with large nonce: %v", err)
645+
}
646+
647+
// Verify the operation was parsed correctly
648+
if op.WorkerAccount != "sminer47" {
649+
t.Errorf("expected worker_account 'sminer47', got %v", op.WorkerAccount)
650+
}
651+
652+
if op.BlockID != "0000fbf357840bfa4e52b569a0498edb20efbe0c" {
653+
t.Errorf("expected block_id '0000fbf357840bfa4e52b569a0498edb20efbe0c', got %v", op.BlockID)
654+
}
655+
656+
// Verify the large nonce value was parsed correctly
657+
if op.Nonce == nil {
658+
t.Fatal("expected nonce to be non-nil")
659+
}
660+
661+
expectedNonce := UInt64(11115213149964598312)
662+
if *op.Nonce != expectedNonce {
663+
t.Errorf("expected nonce %v, got %v", expectedNonce, *op.Nonce)
664+
}
665+
666+
// Verify work was parsed
667+
if op.Work == nil {
668+
t.Fatal("expected work to be non-nil")
669+
}
670+
671+
if op.Work.Worker != "STM6tC4qRjUPKmkqkug5DvSgkeND5DHhnfr3XTgpp4b4nejMEwn9k" {
672+
t.Errorf("expected work.worker 'STM6tC4qRjUPKmkqkug5DvSgkeND5DHhnfr3XTgpp4b4nejMEwn9k', got %v", op.Work.Worker)
673+
}
674+
675+
// Verify props were parsed
676+
if op.Props == nil {
677+
t.Fatal("expected props to be non-nil")
678+
}
679+
680+
if op.Props.MaximumBlockSize != 131072 {
681+
t.Errorf("expected maximum_block_size 131072, got %v", op.Props.MaximumBlockSize)
682+
}
683+
}
684+
685+
func TestPOWOperation_Type(t *testing.T) {
686+
nonce := UInt64(12345)
687+
op := &POWOperation{
688+
WorkerAccount: "worker",
689+
BlockID: "block_id",
690+
Nonce: &nonce,
691+
Work: &POW{
692+
Worker: "STM...",
693+
Input: "input",
694+
Signature: "sig",
695+
Work: "work",
696+
},
697+
Props: &ChainProperties{
698+
AccountCreationFee: "0.100 STEEM",
699+
MaximumBlockSize: 65536,
700+
SBDInterestRate: 1000,
701+
},
702+
}
703+
704+
if op.Type() != TypePOW {
705+
t.Errorf("expected TypePOW, got %v", op.Type())
706+
}
707+
}

0 commit comments

Comments
 (0)