Skip to content

Commit

Permalink
Only process denoms whose original chainID is either the main chain o…
Browse files Browse the repository at this point in the history
…r the current subchain
  • Loading branch information
jieyilong committed Feb 17, 2024
1 parent c25cb9e commit 6c886b2
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions interchain/orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package orchestrator
import (
"context"
"errors"
"fmt"
"math/big"
"sync"
"time"
Expand Down Expand Up @@ -449,6 +450,9 @@ func (oc *Orchestrator) mintTFuelVouchers(txOpts *bind.TransactOpts, targetChain
if dynasty == nil {
return common.Hash{}, ErrDynastyIsNil
}
if !oc.checkChainIDCompatability(se.Denom) {
return common.Hash{}, fmt.Errorf("incompatiable chainID (subchainID: %v, denom: %v)", oc.subchainID, se.Denom)
}
tfuelTokenBank := oc.getTFuelTokenBank(targetChainID)
tx, err := tfuelTokenBank.MintVouchers(txOpts, se.Denom, se.TargetChainVoucherReceiver, se.LockedAmount, dynasty, se.TokenLockNonce)
if err != nil {
Expand All @@ -472,6 +476,9 @@ func (oc *Orchestrator) mintTNT20Vouchers(txOpts *bind.TransactOpts, targetChain
if dynasty == nil {
return common.Hash{}, ErrDynastyIsNil
}
if !oc.checkChainIDCompatability(se.Denom) {
return common.Hash{}, fmt.Errorf("incompatiable chainID (subchainID: %v, denom: %v)", oc.subchainID, se.Denom)
}
TNT20TokenBank := oc.getTNT20TokenBank(targetChainID)
tx, err := TNT20TokenBank.MintVouchers(txOpts, se.Denom, se.Name, se.Symbol, se.Decimals, se.TargetChainVoucherReceiver, se.LockedAmount, dynasty, se.TokenLockNonce)
if err != nil {
Expand All @@ -495,6 +502,9 @@ func (oc *Orchestrator) mintTN721Vouchers(txOpts *bind.TransactOpts, targetChain
if dynasty == nil {
return common.Hash{}, ErrDynastyIsNil
}
if !oc.checkChainIDCompatability(se.Denom) {
return common.Hash{}, fmt.Errorf("incompatiable chainID (subchainID: %v, denom: %v)", oc.subchainID, se.Denom)
}
TNT721TokenBank := oc.getTNT721TokenBank(targetChainID)
tx, err := TNT721TokenBank.MintVouchers(txOpts, se.Denom, se.Name, se.Symbol, se.TargetChainVoucherReceiver, se.TokenID, se.TokenURI, dynasty, se.TokenLockNonce)
if err != nil {
Expand All @@ -518,6 +528,9 @@ func (oc *Orchestrator) mintTN1155Vouchers(txOpts *bind.TransactOpts, targetChai
if dynasty == nil {
return common.Hash{}, ErrDynastyIsNil
}
if !oc.checkChainIDCompatability(se.Denom) {
return common.Hash{}, fmt.Errorf("incompatiable chainID (subchainID: %v, denom: %v)", oc.subchainID, se.Denom)
}
TNT1155TokenBank := oc.getTNT1155TokenBank(targetChainID)
tx, err := TNT1155TokenBank.MintVouchers(txOpts, se.Denom, se.TargetChainVoucherReceiver, se.TokenID, se.LockedAmount, se.TokenURI, dynasty, se.TokenLockNonce)
if err != nil {
Expand All @@ -538,6 +551,9 @@ func (oc *Orchestrator) unlockTFuelTokens(txOpts *bind.TransactOpts, targetChain
if dynasty == nil {
return common.Hash{}, ErrDynastyIsNil
}
if !oc.checkChainIDCompatability(se.Denom) {
return common.Hash{}, fmt.Errorf("incompatiable chainID (subchainID: %v, denom: %v)", oc.subchainID, se.Denom)
}
tfuelTokenBank := oc.getTFuelTokenBank(targetChainID)
tx, err := tfuelTokenBank.UnlockTokens(txOpts, sourceEvent.SourceChainID, se.TargetChainTokenReceiver, se.BurnedAmount, dynasty, se.VoucherBurnNonce)
if err != nil {
Expand All @@ -557,6 +573,9 @@ func (oc *Orchestrator) unlockTNT20Tokens(txOpts *bind.TransactOpts, targetChain
if dynasty == nil {
return common.Hash{}, ErrDynastyIsNil
}
if !oc.checkChainIDCompatability(se.Denom) {
return common.Hash{}, fmt.Errorf("incompatiable chainID (subchainID: %v, denom: %v)", oc.subchainID, se.Denom)
}
TNT20TokenBank := oc.getTNT20TokenBank(targetChainID)
tx, err := TNT20TokenBank.UnlockTokens(txOpts, sourceEvent.SourceChainID, se.Denom, se.TargetChainTokenReceiver, se.BurnedAmount, dynasty, se.VoucherBurnNonce)
if err != nil {
Expand All @@ -576,6 +595,9 @@ func (oc *Orchestrator) unlockTNT721Tokens(txOpts *bind.TransactOpts, targetChai
if dynasty == nil {
return common.Hash{}, ErrDynastyIsNil
}
if !oc.checkChainIDCompatability(se.Denom) {
return common.Hash{}, fmt.Errorf("incompatiable chainID (subchainID: %v, denom: %v)", oc.subchainID, se.Denom)
}
TNT721TokenBank := oc.getTNT721TokenBank(targetChainID)
tx, err := TNT721TokenBank.UnlockTokens(txOpts, sourceEvent.SourceChainID, se.Denom, se.TargetChainTokenReceiver, se.TokenID, dynasty, se.VoucherBurnNonce)
if err != nil {
Expand All @@ -595,6 +617,9 @@ func (oc *Orchestrator) unlockTNT1155Tokens(txOpts *bind.TransactOpts, targetCha
if dynasty == nil {
return common.Hash{}, ErrDynastyIsNil
}
if !oc.checkChainIDCompatability(se.Denom) {
return common.Hash{}, fmt.Errorf("incompatiable chainID (subchainID: %v, denom: %v)", oc.subchainID, se.Denom)
}
TNT1155TokenBank := oc.getTNT1155TokenBank(targetChainID)
tx, err := TNT1155TokenBank.UnlockTokens(txOpts, sourceEvent.SourceChainID, se.Denom, se.TargetChainTokenReceiver, se.TokenID, se.BurnedAmount, dynasty, se.VoucherBurnNonce)
if err != nil {
Expand All @@ -605,6 +630,19 @@ func (oc *Orchestrator) unlockTNT1155Tokens(txOpts *bind.TransactOpts, targetCha
return txHash, nil
}

func (oc *Orchestrator) checkChainIDCompatability(denom string) bool {
originalChainID, err := score.ExtractOriginatedChainIDFromDenom(denom)
if err != nil {
return false
}

compatible := (oc.mainchainID.Cmp(originalChainID) == 0) || (oc.subchainID.Cmp(originalChainID) == 0)

logger.Debugf("denom: %v, originalChainID: %v, mainchainID: %v, suchainID: %v, compatible: %v",
denom, originalChainID, oc.mainchainID, oc.subchainID, compatible)
return compatible
}

func (oc *Orchestrator) buildTxOpts(chainID *big.Int, ecClient *ec.Client) (*bind.TransactOpts, error) {
var gasPrice *big.Int
var err error
Expand Down

0 comments on commit 6c886b2

Please sign in to comment.