@@ -11,6 +11,7 @@ import (
1111 "github.com/ethereum/go-ethereum/accounts/abi/bind"
1212 "github.com/ethereum/go-ethereum/common"
1313 "sort"
14+ "strconv"
1415 "sync"
1516)
1617
@@ -50,7 +51,11 @@ func (dcw *DataCompressorWrapper) getDataCompressorIndex(blockNum int64) string
5051 return name
5152}
5253
54+ // the data compressor are added in increasing order of blockNum
5355func (dcw * DataCompressorWrapper ) AddDataCompressor (blockNum int64 , addr string ) {
56+ if len (dcw .DCBlockNum ) > 0 && dcw .DCBlockNum [len (dcw .DCBlockNum )- 1 ] >= blockNum {
57+ log .Fatal ("Current dc added at :%v, new dc:%s added at %d " , dcw .DCBlockNum , addr , blockNum )
58+ }
5459 chainId , err := dcw .client .ChainID (context .TODO ())
5560 log .CheckFatal (err )
5661 var key string
@@ -67,9 +72,27 @@ func (dcw *DataCompressorWrapper) AddDataCompressor(blockNum int64, addr string)
6772 dcw .BlockNumToName [blockNum ] = key
6873 dcw .NameToAddr [key ] = addr
6974 dcw .DCBlockNum = append (dcw .DCBlockNum , blockNum )
70- arr := dcw .DCBlockNum
71- sort .Slice (arr , func (i , j int ) bool { return arr [i ] < arr [j ] })
72- dcw .DCBlockNum = arr
75+ }
76+
77+ func (dcw * DataCompressorWrapper ) LoadMultipleDC (multiDCs interface {}) {
78+ dcMap , ok := (multiDCs ).(map [string ]interface {})
79+ if ! ok {
80+ log .Fatalf ("Converting address provider() details for dc to map failed %v" , multiDCs )
81+ }
82+ var blockNums []int64
83+ for k := range dcMap {
84+ blockNum , err := strconv .ParseInt (k , 10 , 64 )
85+ if err != nil {
86+ log .Fatal (err )
87+ }
88+ blockNums = append (blockNums , blockNum )
89+ }
90+ sort .Slice (blockNums , func (i , j int ) bool { return blockNums [i ] < blockNums [j ] })
91+ for _ , blockNum := range blockNums {
92+ k := fmt .Sprintf ("%d" , blockNum )
93+ dcAddr := dcMap [k ]
94+ dcw .AddDataCompressor (blockNum , dcAddr .(string ))
95+ }
7396}
7497
7598func (dcw * DataCompressorWrapper ) GetCreditAccountDataExtended (opts * bind.CallOpts , creditManager common.Address , borrower common.Address ) (mainnet.DataTypesCreditAccountDataExtended , error ) {
0 commit comments