Skip to content

Commit 22ab865

Browse files
author
pavel.soloviev
committed
Implemented chaining txs
1 parent 0f78fef commit 22ab865

File tree

11 files changed

+541
-1800
lines changed

11 files changed

+541
-1800
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/storage/swap.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@ func (d *DataBase) GetSwapByTxHash(txHash string) (*Swap, error) {
5555
return swap, nil
5656
}
5757

58-
// GetSwapByTxHash ...
59-
func (d *DataBase) GetSwapByTxHash(txHash string) (*Swap, error) {
60-
swap := &Swap{}
61-
if err := d.db.Where("tx_hash = ? and status in (?)", txHash,
62-
[]SwapStatus{SwapStatusDepositConfirmed, SwapStatusClaimSent, SwapStatusClaimConfirmed, SwapStatusClaimSentFailed, SwapStatusDepositFailed, SwapStatusPassedConfirmed, SwapStatusPassedSent, SwapStatusSpendSent, SwapStatusSpendConfirmed, SwapStatusRejected}).
63-
Find(&swap).Error; err != nil {
64-
return nil, err
65-
}
66-
67-
return swap, nil
68-
}
69-
7058
// UpdateSwapStatus ...
7159
func (d *DataBase) UpdateSwapStatus(swap *Swap, status SwapStatus, rOutAmount string) {
7260
swap.Status = status

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
@@ -223,7 +223,7 @@ func (w *Erc20Worker) GetHeight() (int64, error) {
223223
}
224224

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

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

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
}

0 commit comments

Comments
 (0)