Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crosschain 1 #40

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/service/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ func (r *RelayerSRV) sendClaim(worker workers.IWorker, swap *storage.Swap) (stri
return "", fmt.Errorf("could not send claim tx: %s", err)
}

resID := swap.ResourceID
if swap.DestinationChainID == r.laWorker.GetDestinationID() {
_, resID = utils.GetGasSwapResourceIDs(swap.ResourceID)
} else {
resID, _ = utils.GetGasSwapResourceIDs(swap.ResourceID)
}
resID := utils.GetCurrentStep(swap.ResourceID, swap.StepIndex)
originDecimals, err := originWorker.GetDecimalsFromResourceID(resID)
if err != nil {
println("error in decimals", err.Error())
Expand Down Expand Up @@ -99,7 +94,7 @@ func (r *RelayerSRV) sendClaim(worker workers.IWorker, swap *storage.Swap) (stri
swap.DepositNonce, swap.SenderAddr, amount, swap.ResourceID)

txHash, nonce, err := worker.Vote(swap.DepositNonce, utils.StringToBytes8(swap.OriginChainID), utils.StringToBytes8(swap.DestinationChainID),
utils.StringToBytes32(swap.ResourceID), swap.ReceiverAddr, amount)
utils.StringToBytes32(swap.ResourceID), swap.StepIndex, swap.ReceiverAddr, amount)
if err != nil {
txSent.ErrMsg = err.Error()
txSent.Status = storage.TxSentStatusNotFound
Expand Down
1 change: 1 addition & 0 deletions src/service/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func (r *RelayerSRV) ConfirmWorkerTx(worker workers.IWorker) {
InTokenAddr: txLog.InTokenAddr,
DepositNonce: txLog.DepositNonce,
ResourceID: txLog.ResourceID,
StepIndex: txLog.StepIndex,
OutAmount: txLog.OutAmount,
DestinationChainID: txLog.DestinationChainID,
OriginChainID: txLog.OriginСhainID,
Expand Down
2 changes: 2 additions & 0 deletions src/service/storage/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type TxLog struct {
DestinationChainID string `gorm:"type:TEXT"`
DepositNonce uint64 `gorm:"type:BIGINT"`
ResourceID string `gorm:"type:TEXT"`
StepIndex uint8 `gorm:"type:BIGINT"`
SwapStatus SwapStatus `gorm:"type:TEXT"`
ExpireHeight int64 `gorm:"type:BIGINT"`
Timestamp int64 `gorm:"type:BIGINT"`
Expand Down Expand Up @@ -59,6 +60,7 @@ type Swap struct {
RelayerOutAmount string
DepositNonce uint64
ResourceID string
StepIndex uint8
// ExpireHeight int64
Height int64
// Timestamp int64
Expand Down
1,024 changes: 276 additions & 748 deletions src/service/workers/eth-compatible/abi/bridge/la/Bridge.go

Large diffs are not rendered by default.

405 changes: 235 additions & 170 deletions src/service/workers/eth-compatible/abi/handler/eth/Handler.go

Large diffs are not rendered by default.

74 changes: 37 additions & 37 deletions src/service/workers/eth-compatible/abi/handler/la/Handler.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/service/workers/eth-compatible/erc20-worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (w *Erc20Worker) GetHeight() (int64, error) {
}

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

value, _ := new(big.Int).SetString(amount, 10)
tx, err := instance.VoteProposal(auth, originchainID, destinationChainID, depositNonce, resourceID, common.HexToAddress(receiptAddr), value)
tx, err := instance.VoteProposal(auth, originchainID, destinationChainID, depositNonce, resourceID, common.HexToAddress(receiptAddr), value, []byte{stepIndex})
if err != nil {
return "", 0, err
}
Expand Down
1 change: 1 addition & 0 deletions src/service/workers/eth-compatible/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (ev DepositEvent) ToTxLog() *storage.TxLog {
OriginСhainID: common.Bytes2Hex(ev.OriginChainID[:]),
SwapID: utils.CalcutateSwapID(common.Bytes2Hex(ev.OriginChainID[:]), common.Bytes2Hex(ev.DestinationChainID[:]), fmt.Sprint(ev.DepositNonce)),
ResourceID: common.Bytes2Hex(ev.ResourceID[:]),
StepIndex: ev.Params[0],
DepositNonce: ev.DepositNonce,
SenderAddr: ev.Depositor.Hex(),
ReceiverAddr: ev.RecipientAddress.Hex(),
Expand Down
12 changes: 2 additions & 10 deletions src/service/workers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package utils

import (
"crypto/ecdsa"
"encoding/hex"
"math"
"math/big"

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

func GetGasSwapResourceIDs(resourceID string) (destResourceID, originResourceID string) {
swapIdentifier := hex.EncodeToString([]byte("swap"))
if resourceID[:8] == swapIdentifier {
originResourceID = "00000000000000000000000000000000000000000000" + resourceID[44:]
destResourceID = "00000000000000000000000000000000000000000000" + resourceID[24:44]
return destResourceID, originResourceID
} else {
return resourceID, resourceID
}
func GetCurrentStep(resourceID string, stepIndex uint8) string {
return resourceID[16*stepIndex:16*stepIndex+8] + "00000000000000000000000000000000000000000000000000000000"
}
2 changes: 1 addition & 1 deletion src/service/workers/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ type IWorker interface {
// CreateRequest sends wrapped tokens tx
// CreateRequest(swapID common.Hash) (string, error)
// Vote
Vote(depositNonce uint64, originChainID [8]byte, destinationChainID [8]byte, resourceID [32]byte, receiptAddr string, amount string) (string, uint64, error)
Vote(depositNonce uint64, originChainID [8]byte, destinationChainID [8]byte, resourceID [32]byte, stepIndex uint8, receiptAddr string, amount string) (string, uint64, error)
}