@@ -614,20 +614,43 @@ func getEpochReward(account common.Address, header *types.Header) (AccountEpochR
614614 return epochReward , nil
615615}
616616
617+ // jsonNumberToBigInt parses a json.Number into a *big.Int, handling both plain
618+ // decimal strings (e.g. "4500000000000000000") and scientific notation
619+ // (e.g. "4.5e+21") that big.Int.SetString cannot parse directly.
620+ func jsonNumberToBigInt (n json.Number ) (* big.Int , bool ) {
621+ s := n .String ()
622+ // Try plain integer first — the common case.
623+ if i , ok := new (big.Int ).SetString (s , 10 ); ok {
624+ return i , true
625+ }
626+ // Fall back to big.Float to handle scientific notation.
627+ f , _ , err := new (big.Float ).SetPrec (256 ).Parse (s , 10 )
628+ if err != nil {
629+ log .Warn ("[jsonNumberToBigInt] Failed to parse json.Number:" , "number" , s , "err" , err )
630+ return nil , false
631+ }
632+
633+ i , acc := f .Int (nil )
634+ if acc != big .Exact {
635+ // The value had a fractional part; truncate is the best we can do
636+ log .Warn ("[jsonNumberToBigInt] json.Number is not an exact integer value" , "number" , s , "truncated" , i .String (), "accuracy" , acc )
637+ }
638+
639+ return i , true
640+ }
641+
617642func (rewardObj * AccountEpochReward ) getRewardAndStatus (account string , data map [string ]interface {}) {
618643 if signersData , exists := data ["signers" ]; exists {
619644 if accountData , ok := signersData .(map [string ]interface {})[account ]; ok {
620645 nodeReward := accountData .(map [string ]interface {})["reward" ]
621646 delegatedReward := data ["rewards" ].(map [string ]interface {})[account ]
622647 rewardObj .AccountStatus = statusMasternode
623- nodeRewardBigInt , ok := new (big.Int ).SetString (nodeReward .(json.Number ).String (), 10 )
624- if ok {
648+ if nodeRewardBigInt , ok := jsonNumberToBigInt (nodeReward .(json.Number )); ok {
625649 rewardObj .AccountReward = nodeRewardBigInt
626650 }
627651
628652 for k , v := range delegatedReward .(map [string ]interface {}) {
629- delegatedBigInt , ok := new (big.Int ).SetString (v .(json.Number ).String (), 10 )
630- if ok {
653+ if delegatedBigInt , ok := jsonNumberToBigInt (v .(json.Number )); ok {
631654 rewardObj .DelegatedReward [k ] = delegatedBigInt
632655 }
633656 }
@@ -640,14 +663,12 @@ func (rewardObj *AccountEpochReward) getRewardAndStatus(account string, data map
640663 nodeReward := accountData .(map [string ]interface {})["reward" ]
641664 delegatedReward := data ["rewardsProtector" ].(map [string ]interface {})[account ]
642665 rewardObj .AccountStatus = statusProtectornode
643- nodeRewardBigInt , successSetNodeReward := new (big.Int ).SetString (nodeReward .(json.Number ).String (), 10 )
644- if successSetNodeReward {
666+ if nodeRewardBigInt , ok := jsonNumberToBigInt (nodeReward .(json.Number )); ok {
645667 rewardObj .AccountReward = nodeRewardBigInt
646668 }
647669
648670 for k , v := range delegatedReward .(map [string ]interface {}) {
649- delegatedBigInt , successSetDelegatedReward := new (big.Int ).SetString (v .(json.Number ).String (), 10 )
650- if successSetDelegatedReward {
671+ if delegatedBigInt , ok := jsonNumberToBigInt (v .(json.Number )); ok {
651672 rewardObj .DelegatedReward [k ] = delegatedBigInt
652673 }
653674 }
@@ -660,14 +681,12 @@ func (rewardObj *AccountEpochReward) getRewardAndStatus(account string, data map
660681 nodeReward := accountData .(map [string ]interface {})["reward" ]
661682 delegatedReward := data ["rewardsObserver" ].(map [string ]interface {})[account ]
662683 rewardObj .AccountStatus = statusObservernode
663- nodeRewardBigInt , successSetNodeReward := new (big.Int ).SetString (nodeReward .(json.Number ).String (), 10 )
664- if successSetNodeReward {
684+ if nodeRewardBigInt , ok := jsonNumberToBigInt (nodeReward .(json.Number )); ok {
665685 rewardObj .AccountReward = nodeRewardBigInt
666686 }
667687
668688 for k , v := range delegatedReward .(map [string ]interface {}) {
669- delegatedBigInt , successSetDelegatedReward := new (big.Int ).SetString (v .(json.Number ).String (), 10 )
670- if successSetDelegatedReward {
689+ if delegatedBigInt , ok := jsonNumberToBigInt (v .(json.Number )); ok {
671690 rewardObj .DelegatedReward [k ] = delegatedBigInt
672691 }
673692 }
0 commit comments