Skip to content

Commit b37b3e5

Browse files
committed
big endian bug
1 parent 3c14e69 commit b37b3e5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

extractors/susy/bridge/ergo.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package bridge
33
import (
44
"context"
55
"encoding/base64"
6+
"encoding/binary"
67
"fmt"
78
"github.com/Gravity-Tech/gravity-node-data-extractor/v2/extractors"
89
"github.com/Gravity-Tech/gravity-node-data-extractor/v2/helpers"
@@ -144,14 +145,15 @@ func (provider *ErgoToErgoExtractionBridge) ExtractDirectTransferRequest(ctx con
144145
//newAmount := int64(float64(amount) * sourceDecimals / destinationDecimals)
145146
newAmount := bigAmount.
146147
Mul(bigAmount, destinationDecimals).
147-
Div(bigAmount, sourceDecimals)
148+
Div(bigAmount, sourceDecimals).Int64()
148149
fmt.Println(newAmount)
149150

150151
result := []byte{'m'}
151152
newAmountBytes := make([]byte, 32)
153+
binary.BigEndian.PutUint64(newAmountBytes, uint64(newAmount))
152154
var RequestIdBytes [32]byte
153155
result = append(result, rqId.FillBytes(RequestIdBytes[:])...)
154-
result = append(result, newAmount.FillBytes(newAmountBytes[:])...)
156+
result = append(result, newAmountBytes[:]...)
155157
receiver := []byte(rq.Receiver)
156158
result = append(result, receiver[:]...)
157159

@@ -191,14 +193,16 @@ func (provider *ErgoToErgoExtractionBridge) ExtractReverseTransferRequest(ctx co
191193

192194
//newAmount := int64(float64(amount) * sourceDecimals / destinationDecimals)
193195
newAmount := bigAmount.
194-
Mul(bigAmount, sourceDecimals).
195-
Div(bigAmount, destinationDecimals)
196+
Mul(bigAmount, destinationDecimals).
197+
Div(bigAmount, sourceDecimals).Int64()
198+
fmt.Println(newAmount)
196199

197-
result := []byte{'u'}
200+
result := []byte{'m'}
198201
newAmountBytes := make([]byte, 32)
202+
binary.BigEndian.PutUint64(newAmountBytes, uint64(newAmount))
199203
var RequestIdBytes [32]byte
200204
result = append(result, rqId.FillBytes(RequestIdBytes[:])...)
201-
result = append(result, newAmount.FillBytes(newAmountBytes[:])...)
205+
result = append(result, newAmountBytes[:]...)
202206
receiver := []byte(rq.Receiver)
203207
result = append(result, receiver[:]...)
204208

0 commit comments

Comments
 (0)