@@ -28,12 +28,13 @@ type kleverBlockchainProposedTransfer struct {
2828
2929// Transfer -
3030type Transfer struct {
31- From []byte
32- To []byte
33- Token string
34- Amount * big.Int
35- Nonce * big.Int
36- Data []byte
31+ From []byte
32+ To []byte
33+ Token string
34+ Amount * big.Int
35+ ConvertedAmount * big.Int
36+ Nonce * big.Int
37+ Data []byte
3738}
3839
3940// KleverBlockchainPendingBatch -
@@ -44,11 +45,12 @@ type KleverBlockchainPendingBatch struct {
4445
4546// KleverBlockchainDeposit -
4647type KleverBlockchainDeposit struct {
47- From address.Address
48- To common.Address
49- Ticker string
50- Amount * big.Int
51- DepositNonce uint64
48+ From address.Address
49+ To common.Address
50+ Ticker string
51+ Amount * big.Int
52+ ConvertedAmount * big.Int
53+ DepositNonce uint64
5254}
5355
5456// kleverBlockchainContractStateMock is not concurrent safe
@@ -193,26 +195,32 @@ func (mock *kleverBlockchainContractStateMock) createProposedTransfer(dataSplit
193195 panic (errDecode )
194196 }
195197
196- nonceBytes , errDecode := hex .DecodeString (dataSplit [currentIndex + 4 ])
198+ convertedAmountBytes , errDecode := hex .DecodeString (dataSplit [currentIndex + 4 ])
197199 if errDecode != nil {
198200 panic (errDecode )
199201 }
200202
201- dataBytes , errDecode := hex .DecodeString (dataSplit [currentIndex + 5 ])
203+ nonceBytes , errDecode := hex .DecodeString (dataSplit [currentIndex + 5 ])
204+ if errDecode != nil {
205+ panic (errDecode )
206+ }
207+
208+ dataBytes , errDecode := hex .DecodeString (dataSplit [currentIndex + 6 ])
202209 if errDecode != nil {
203210 panic (errDecode )
204211 }
205212
206213 t := Transfer {
207- From : from ,
208- To : to ,
209- Token : dataSplit [currentIndex + 2 ],
210- Amount : big .NewInt (0 ).SetBytes (amountBytes ),
211- Nonce : big .NewInt (0 ).SetBytes (nonceBytes ),
212- Data : dataBytes ,
214+ From : from ,
215+ To : to ,
216+ Token : dataSplit [currentIndex + 2 ],
217+ Amount : big .NewInt (0 ).SetBytes (amountBytes ),
218+ ConvertedAmount : big .NewInt (0 ).SetBytes (convertedAmountBytes ),
219+ Nonce : big .NewInt (0 ).SetBytes (nonceBytes ),
220+ Data : dataBytes ,
213221 }
214222
215- indexIncrementValue := 6
223+ indexIncrementValue := 7
216224 transfer .Transfers = append (transfer .Transfers , t )
217225 currentIndex += indexIncrementValue
218226 }
@@ -283,6 +291,8 @@ func (mock *kleverBlockchainContractStateMock) processVmRequests(vmRequest *mode
283291 return mock .vmRequestGetBurnBalances (vmRequest ), nil
284292 case "getLastBatchId" :
285293 return mock .vmRequestGetLastBatchId (vmRequest ), nil
294+ case "convertEthToKdaAmount" :
295+ return mock .vmRequestConvertEthToKdaAmount (vmRequest ), nil
286296 }
287297
288298 return nil , fmt .Errorf ("unimplemented function: %s" , vmRequest .FuncName )
@@ -464,6 +474,11 @@ func (mock *kleverBlockchainContractStateMock) responseWithPendingBatch() *model
464474 args = append (args , deposit .To .Bytes ())
465475 args = append (args , []byte (deposit .Ticker ))
466476 args = append (args , deposit .Amount .Bytes ())
477+ convertedAmount := deposit .ConvertedAmount
478+ if convertedAmount == nil {
479+ convertedAmount = deposit .Amount // default to same as Amount if not set
480+ }
481+ args = append (args , convertedAmount .Bytes ())
467482 }
468483 return createOkVmResponse (args )
469484}
@@ -553,6 +568,23 @@ func (mock *kleverBlockchainContractStateMock) vmRequestGetLastBatchId(_ *models
553568 return createOkVmResponse ([][]byte {mock .pendingBatch .Nonce .Bytes ()})
554569}
555570
571+ func (mock * kleverBlockchainContractStateMock ) vmRequestConvertEthToKdaAmount (vmRequest * models.VmValueRequest ) * models.VmValuesResponseData {
572+ // Parse the token from the first argument
573+ hexedToken := vmRequest .Args [0 ]
574+
575+ // Parse the amount from the second argument
576+ amountBytes , err := hex .DecodeString (vmRequest .Args [1 ])
577+ if err != nil {
578+ return createNokVmResponse (err )
579+ }
580+ amount := big .NewInt (0 ).SetBytes (amountBytes )
581+
582+ // Use the decimal conversion configuration from the token registry
583+ convertedAmount := mock .tokensRegistryMock .getConvertedAmount (hexedToken , amount )
584+
585+ return createOkVmResponse ([][]byte {convertedAmount .Bytes ()})
586+ }
587+
556588func getBigIntFromString (data string ) * big.Int {
557589 buff , err := hex .DecodeString (data )
558590 if err != nil {
0 commit comments