@@ -11,26 +11,42 @@ import (
1111 "github.com/smartcontractkit/chainlink-protos/cre/go/values/pb"
1212)
1313
14- // Helper function to convert protobuf BigInt to big.Int
14+ // Helper function to convert protobuf BigInt to big.Int, preserves nil
1515func pbBigIntToInt (b * ccipocr3pb.BigInt ) * big.Int {
16- if b == nil || len (b .Value ) == 0 {
16+ if b == nil {
17+ return nil
18+ }
19+
20+ if b .Value == nil {
21+ return nil
22+ }
23+
24+ if len (b .Value ) == 0 {
1725 return big .NewInt (0 )
1826 }
1927 return new (big.Int ).SetBytes (b .Value )
2028}
2129
2230// Helper function to convert protobuf BigInt to ccipocr3.BigInt, preserving nil
2331func pbToBigInt (b * ccipocr3pb.BigInt ) ccipocr3.BigInt {
24- if b == nil || len (b .Value ) == 0 {
32+ if b == nil {
33+ return ccipocr3.BigInt {Int : nil }
34+ }
35+
36+ if b .Value == nil {
2537 return ccipocr3.BigInt {Int : nil }
2638 }
39+
40+ if len (b .Value ) == 0 {
41+ return ccipocr3.BigInt {Int : big .NewInt (0 )}
42+ }
2743 return ccipocr3 .NewBigInt (new (big.Int ).SetBytes (b .Value ))
2844}
2945
3046// Helper function to convert big.Int to protobuf BigInt
3147func intToPbBigInt (i * big.Int ) * ccipocr3pb.BigInt {
3248 if i == nil {
33- return & ccipocr3pb. BigInt { Value : [] byte {}}
49+ return nil
3450 }
3551 return & ccipocr3pb.BigInt {Value : i .Bytes ()}
3652}
@@ -743,20 +759,13 @@ func pbToCurseInfo(pb *ccipocr3pb.CurseInfo) ccipocr3.CurseInfo {
743759 return result
744760}
745761
746- func pbToBigIntPreservingZero (b * ccipocr3pb.BigInt ) ccipocr3.BigInt {
747- if b == nil {
748- return ccipocr3.BigInt {Int : nil }
749- }
750- return ccipocr3 .NewBigInt (new (big.Int ).SetBytes (b .Value ))
751- }
752-
753762func pbToTokenPriceMap (pbMap map [string ]* ccipocr3pb.BigInt ) ccipocr3.TokenPriceMap {
754763 if pbMap == nil {
755764 return nil
756765 }
757766 result := make (ccipocr3.TokenPriceMap )
758767 for token , pbPrice := range pbMap {
759- result [ccipocr3 .UnknownEncodedAddress (token )] = pbToBigIntPreservingZero (pbPrice )
768+ result [ccipocr3 .UnknownEncodedAddress (token )] = pbToBigInt (pbPrice )
760769 }
761770 return result
762771}
@@ -790,7 +799,7 @@ func pbToMessageTokenIDMap(pbTokens map[string]*ccipocr3pb.RampTokenAmount) (map
790799 SourcePoolAddress : pbAmount .SourcePoolAddress ,
791800 DestTokenAddress : pbAmount .DestTokenAddress ,
792801 ExtraData : pbAmount .ExtraData ,
793- Amount : pbToBigIntPreservingZero (pbAmount .Amount ),
802+ Amount : pbToBigInt (pbAmount .Amount ),
794803 }
795804 }
796805 return result , nil
0 commit comments