Skip to content

Commit 52140ca

Browse files
author
pavel.soloviev
committed
Implemented chaining txs
1 parent 6261e47 commit 52140ca

File tree

10 files changed

+541
-1788
lines changed

10 files changed

+541
-1788
lines changed

src/service/claim.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,7 @@ func (r *RelayerSRV) sendClaim(worker workers.IWorker, swap *storage.Swap) (stri
5959
return "", fmt.Errorf("could not send claim tx: %s", err)
6060
}
6161

62-
resID := swap.ResourceID
63-
if swap.DestinationChainID == r.laWorker.GetDestinationID() {
64-
_, resID = utils.GetGasSwapResourceIDs(swap.ResourceID)
65-
} else {
66-
resID, _ = utils.GetGasSwapResourceIDs(swap.ResourceID)
67-
}
62+
resID := utils.GetCurrentStep(swap.ResourceID, swap.StepIndex)
6863
originDecimals, err := originWorker.GetDecimalsFromResourceID(resID)
6964
if err != nil {
7065
println("error in decimals", err.Error())
@@ -99,7 +94,7 @@ func (r *RelayerSRV) sendClaim(worker workers.IWorker, swap *storage.Swap) (stri
9994
swap.DepositNonce, swap.SenderAddr, amount, swap.ResourceID)
10095

10196
txHash, nonce, err := worker.Vote(swap.DepositNonce, utils.StringToBytes8(swap.OriginChainID), utils.StringToBytes8(swap.DestinationChainID),
102-
utils.StringToBytes32(swap.ResourceID), swap.ReceiverAddr, amount)
97+
utils.StringToBytes32(swap.ResourceID), swap.StepIndex, swap.ReceiverAddr, amount)
10398
if err != nil {
10499
txSent.ErrMsg = err.Error()
105100
txSent.Status = storage.TxSentStatusNotFound

src/service/relayer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func (r *RelayerSRV) ConfirmWorkerTx(worker workers.IWorker) {
152152
InTokenAddr: txLog.InTokenAddr,
153153
DepositNonce: txLog.DepositNonce,
154154
ResourceID: txLog.ResourceID,
155+
StepIndex: txLog.StepIndex,
155156
OutAmount: txLog.OutAmount,
156157
DestinationChainID: txLog.DestinationChainID,
157158
OriginChainID: txLog.OriginСhainID,

src/service/storage/models.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type TxLog struct {
3232
DestinationChainID string `gorm:"type:TEXT"`
3333
DepositNonce uint64 `gorm:"type:BIGINT"`
3434
ResourceID string `gorm:"type:TEXT"`
35+
StepIndex uint8 `gorm:"type:UINT"`
3536
SwapStatus SwapStatus `gorm:"type:TEXT"`
3637
ExpireHeight int64 `gorm:"type:BIGINT"`
3738
Timestamp int64 `gorm:"type:BIGINT"`
@@ -59,6 +60,7 @@ type Swap struct {
5960
RelayerOutAmount string
6061
DepositNonce uint64
6162
ResourceID string
63+
StepIndex uint8
6264
// ExpireHeight int64
6365
Height int64
6466
// Timestamp int64

src/service/workers/eth-compatible/abi/bridge/la/Bridge.go

Lines changed: 258 additions & 1561 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/service/workers/eth-compatible/abi/handler/eth/Handler.go

Lines changed: 235 additions & 170 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/service/workers/eth-compatible/abi/handler/la/Handler.go

Lines changed: 37 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/service/workers/eth-compatible/erc20-worker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func (w *Erc20Worker) GetHeight() (int64, error) {
222222
}
223223

224224
// Vote ...
225-
func (w *Erc20Worker) Vote(depositNonce uint64, originchainID [8]byte, destinationChainID [8]byte, resourceID [32]byte, receiptAddr string, amount string) (string, uint64, error) {
225+
func (w *Erc20Worker) Vote(depositNonce uint64, originchainID [8]byte, destinationChainID [8]byte, resourceID [32]byte, stepIndex uint8, receiptAddr string, amount string) (string, uint64, error) {
226226
auth, err := w.getTransactor()
227227
if err != nil {
228228
return "", 0, err
@@ -234,7 +234,7 @@ func (w *Erc20Worker) Vote(depositNonce uint64, originchainID [8]byte, destinati
234234
}
235235

236236
value, _ := new(big.Int).SetString(amount, 10)
237-
tx, err := instance.VoteProposal(auth, originchainID, destinationChainID, depositNonce, resourceID, common.HexToAddress(receiptAddr), value)
237+
tx, err := instance.VoteProposal(auth, originchainID, destinationChainID, depositNonce, resourceID, common.HexToAddress(receiptAddr), value, []byte{stepIndex})
238238
if err != nil {
239239
return "", 0, err
240240
}

src/service/workers/eth-compatible/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func (ev DepositEvent) ToTxLog() *storage.TxLog {
7272
OriginСhainID: common.Bytes2Hex(ev.OriginChainID[:]),
7373
SwapID: utils.CalcutateSwapID(common.Bytes2Hex(ev.OriginChainID[:]), common.Bytes2Hex(ev.DestinationChainID[:]), fmt.Sprint(ev.DepositNonce)),
7474
ResourceID: common.Bytes2Hex(ev.ResourceID[:]),
75+
StepIndex: ev.Params[0],
7576
DepositNonce: ev.DepositNonce,
7677
SenderAddr: ev.Depositor.Hex(),
7778
ReceiverAddr: ev.RecipientAddress.Hex(),

src/service/workers/utils/utils.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package utils
22

33
import (
44
"crypto/ecdsa"
5-
"encoding/hex"
65
"math"
76
"math/big"
87

@@ -85,13 +84,6 @@ func ConvertDecimals(originDecimals, destDecimals uint8, amount string) string {
8584
return new(big.Int).Quo(new(big.Int).Mul(amountInFloat, dest), origin).String()
8685
}
8786

88-
func GetGasSwapResourceIDs(resourceID string) (destResourceID, originResourceID string) {
89-
swapIdentifier := hex.EncodeToString([]byte("swap"))
90-
if resourceID[:8] == swapIdentifier {
91-
originResourceID = "00000000000000000000000000000000000000000000" + resourceID[44:]
92-
destResourceID = "00000000000000000000000000000000000000000000" + resourceID[24:44]
93-
return destResourceID, originResourceID
94-
} else {
95-
return resourceID, resourceID
96-
}
87+
func GetCurrentStep(resourceID string, stepIndex uint8) string {
88+
return resourceID[16*stepIndex:16*stepIndex+8] + "00000000000000000000000000000000000000000000000000000000"
9789
}

src/service/workers/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ type IWorker interface {
5454
// CreateRequest sends wrapped tokens tx
5555
// CreateRequest(swapID common.Hash) (string, error)
5656
// Vote
57-
Vote(depositNonce uint64, originChainID [8]byte, destinationChainID [8]byte, resourceID [32]byte, receiptAddr string, amount string) (string, uint64, error)
57+
Vote(depositNonce uint64, originChainID [8]byte, destinationChainID [8]byte, resourceID [32]byte, stepIndex uint8, receiptAddr string, amount string) (string, uint64, error)
5858
}

0 commit comments

Comments
 (0)