Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
830 changes: 27 additions & 803 deletions app/clients/evm/contracts/router/diamond-router.go

Large diffs are not rendered by default.

1,271 changes: 0 additions & 1,271 deletions app/clients/evm/contracts/werc721/werc721.go

This file was deleted.

26 changes: 0 additions & 26 deletions app/clients/hedera/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,6 @@ func (hc Node) SubmitScheduledHbarTransferTransaction(
return hc.submitScheduledTransferTransaction(payerAccountID, memo, transferTransaction)
}

func (hc Node) SubmitScheduledNftTransferTransaction(
nftID hedera.NftID,
payerAccount hedera.AccountID,
sender hedera.AccountID,
receiving hedera.AccountID,
memo string, approved bool) (*hedera.TransactionResponse, error) {

transferTransaction := hedera.
NewTransferTransaction().
AddApprovedNftTransfer(nftID, sender, receiving, approved)

return hc.submitScheduledTransferTransaction(payerAccount, memo, transferTransaction)
}

func (hc Node) TransactionReceiptQuery(transactionID hedera.TransactionID, nodeAccIds []hedera.AccountID) (hedera.TransactionReceipt, error) {
return hedera.NewTransactionReceiptQuery().
SetTransactionID(transactionID).
Expand All @@ -225,18 +211,6 @@ func (hc Node) TransactionReceiptQuery(transactionID hedera.TransactionID, nodeA
Execute(hc.GetClient())
}

func (hc Node) SubmitScheduledNftApproveTransaction(
payer hedera.AccountID,
memo string,
nftId hedera.NftID,
owner hedera.AccountID,
spender hedera.AccountID) (*hedera.TransactionResponse, error) {
tx := hedera.NewAccountAllowanceApproveTransaction().
ApproveTokenNftAllowance(nftId, owner, spender)

return hc.submitScheduledAllowTransaction(payer, memo, tx)
}

func (hc Node) submitScheduledAllowTransaction(payer hedera.AccountID, memo string, tx *hedera.AccountAllowanceApproveTransaction) (*hedera.TransactionResponse, error) {
tx, err := tx.FreezeWith(hc.GetClient())
if err != nil {
Expand Down
53 changes: 0 additions & 53 deletions app/clients/hedera/mirror-node/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,33 +227,6 @@ func (c Client) GetMessagesForTopicBetween(topicId hedera.TopicID, from, to int6
return res, nil
}

// GetNftTransactions returns the nft transactions for tokenID and serialNum
func (c Client) GetNftTransactions(tokenID string, serialNum int64) (transaction.NftTransactionsResponse, error) {
query := fmt.Sprintf("%stokens/%s/nfts/%d/transactions", c.mirrorAPIAddress, tokenID, serialNum)

httpResponse, err := c.get(query)
if err != nil {
return transaction.NftTransactionsResponse{}, err
}

bodyBytes, err := readResponseBody(httpResponse)
if err != nil {
return transaction.NftTransactionsResponse{}, err
}

if httpResponse.StatusCode != http.StatusOK {
return transaction.NftTransactionsResponse{}, fmt.Errorf("mirror Node API [%s] ended with Status Code [%d]. Body bytes: [%s]", query, httpResponse.StatusCode, bodyBytes)
}

var response *transaction.NftTransactionsResponse
err = json.Unmarshal(bodyBytes, &response)
if err != nil {
return transaction.NftTransactionsResponse{}, err
}

return *response, nil
}

func (c Client) GetTransaction(transactionID string) (*transaction.Response, error) {
transactionsDownloadQuery := fmt.Sprintf("/%s",
transactionID)
Expand Down Expand Up @@ -324,32 +297,6 @@ func (c Client) GetStateProof(transactionID string) ([]byte, error) {
return readResponseBody(response)
}

func (c Client) GetNft(tokenID string, serialNum int64) (*transaction.Nft, error) {
nftQuery := fmt.Sprintf("%s%d", "/nfts/", serialNum)
query := fmt.Sprintf("%s%s%s%s", c.mirrorAPIAddress, "tokens/", tokenID, nftQuery)

httpResponse, e := c.get(query)
if e != nil {
return nil, e
}
if httpResponse.StatusCode >= 400 {
return nil, fmt.Errorf(`failed to execute query: [%s]. Error: [%s]`, query, query)
}

bodyBytes, e := readResponseBody(httpResponse)
if e != nil {
return nil, e
}

var response *transaction.Nft
e = json.Unmarshal(bodyBytes, &response)
if e != nil {
return nil, e
}

return response, nil
}

func (c Client) AccountExists(accountID hedera.AccountID) bool {
mirrorNodeApiTransactionAddress := fmt.Sprintf("%s%s", c.mirrorAPIAddress, "accounts")
accountQuery := fmt.Sprintf("%s/%s",
Expand Down
65 changes: 5 additions & 60 deletions app/clients/hedera/mirror-node/model/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type (
TransactionID string `json:"transaction_id"`
Transfers []Transfer `json:"transfers"`
TokenTransfers []Transfer `json:"token_transfers"`
NftTransfers []NftTransfer `json:"nft_transfers"`
}
// Transfer struct used by the Hedera Mirror node REST API
Transfer struct {
Expand All @@ -51,13 +50,6 @@ type (
// When retrieving ordinary hbar transfers, this field does not get populated
Token string `json:"token_id"`
}
// NftTransfer struct used by the Hedera mirror node REST API
NftTransfer struct {
ReceiverAccountID string `json:"receiver_account_id"`
SenderAccountID string `json:"sender_account_id"`
SerialNumber int64 `json:"serial_number"`
Token string `json:"token_id"`
}
// Response struct used by the Hedera Mirror node REST API and returned once
// account transactions are queried
Response struct {
Expand All @@ -74,37 +66,12 @@ type (
PayerAccountId string `json:"payer_account_id"`
ScheduleId string `json:"schedule_id"`
}

// Nft struct used by Hedera Mirror node REST API to return information
// for a given Nft entity
Nft struct {
AccountID string `json:"account_id"` // The account ID of the account associated with the NFT
CreatedTimestamp string `json:"created_timestamp"` // The timestamp of when the NFT was created
Deleted bool `json:"deleted"` // Whether the token was deleted or not
Metadata string `json:"metadata"` // The metadata of the NFT, in base64
ModifiedTimestamp string `json:"modified_timestamp"` // The last time the token properties were modified
SerialNumber int64 `json:"serial_number"` // The serial number of the NFT
TokenID string `json:"token_id"` // The token ID of the NFT
}
// NftTransactionsResponse struct used by Hedera Mirror node REST API to return information
// about an NFT's transaction
NftTransactionsResponse struct {
Transactions []NftTransaction `json:"transactions"`
Links Pagination `json:"links"`
}
NftTransaction struct {
TransactionID string `json:"transaction_id"` // The transaction ID of the transaction
Type string `json:"type"` // The type of transaction TOKENBURN, TOKEMINT, CRYPTOTRANSFER
SenderAccountID string `json:"sender_account_id"` // The account that sent the NFT
ReceiverAccountID string `json:"receiver_account_id"` // The account that received the NFT
}
Pagination struct {
Next string `json:"next"` // Hyperlink to the next page of results
}
// ParsedTransfer Used in GetIncomingTransfer to return the information about an Incoming Transfer
ParsedTransfer struct {
IsNft bool
AmountOrSerialNum int64
Amount int64
Asset string
}
)
Expand All @@ -131,16 +98,6 @@ func (t Transaction) getIncomingTokenAmountFor(account string) (int64, string, e
return 0, "", errors.New("no incoming token transfer found")
}

func (t Transaction) getIncomingNftTransferFor(account string) (serialNum int64, token string, err error) {
for _, ntr := range t.NftTransfers {
if ntr.ReceiverAccountID == account {
return ntr.SerialNumber, ntr.Token, nil
}
}

return 0, "", errors.New("no incoming nft transfer found")
}

// GetHBARTransfer gets the HBAR transfer for an Account
func (t Transaction) GetHBARTransfer(account string) (amount int64, isFound bool) {
for _, tr := range t.Transfers {
Expand All @@ -165,33 +122,21 @@ func (t Transaction) GetTokenTransfer(account string) (amount int64, isFound boo

// Process Hedera -> EVM TX
// GetIncomingTransfer returns the transfer to an account in the following order:
// 1. Checks if there is an NFT transfer
// 2. Checks if there is a Fungible Token transfer
// 3. Checks if there is an HBAR transfer
// 1. Checks if there is a Fungible Token transfer
// 2. Checks if there is an HBAR transfer
func (t Transaction) GetIncomingTransfer(account string) (parsed ParsedTransfer, err error) {
serialNum, asset, err := t.getIncomingNftTransferFor(account)
if err == nil {
return ParsedTransfer{
IsNft: true,
AmountOrSerialNum: serialNum,
Asset: asset,
}, nil
}

amount, asset, err := t.getIncomingTokenAmountFor(account)
if err == nil {
return ParsedTransfer{
IsNft: false,
AmountOrSerialNum: amount,
Amount: amount,
Asset: asset,
}, nil
}

amount, asset, err = t.getIncomingAmountFor(account)
if err == nil {
return ParsedTransfer{
IsNft: false,
AmountOrSerialNum: amount,
Amount: amount,
Asset: asset,
}, nil
}
Expand Down
3 changes: 0 additions & 3 deletions app/domain/client/diamond-router.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type DiamondRouter interface {
ParseBurn(log types.Log) (*router.RouterBurn, error)
ParseLock(log types.Log) (*router.RouterLock, error)
ParseUnlock(log types.Log) (*router.RouterUnlock, error)
ParseBurnERC721(log types.Log) (*router.RouterBurnERC721, error)
WatchBurn(opts *bind.WatchOpts, sink chan<- *router.RouterBurn) (event.Subscription, error)
MembersCount(opts *bind.CallOpts) (*big.Int, error)
MemberAt(opts *bind.CallOpts, _index *big.Int) (common.Address, error)
Expand All @@ -43,6 +42,4 @@ type DiamondRouter interface {
PreviousAccrued *big.Int
Accumulator *big.Int
}, error)
Erc721Fee(opts *bind.CallOpts, _erc721 common.Address) (*big.Int, error)
Erc721Payment(opts *bind.CallOpts, _erc721 common.Address) (common.Address, error)
}
31 changes: 0 additions & 31 deletions app/domain/client/evm_nft.go

This file was deleted.

4 changes: 0 additions & 4 deletions app/domain/client/mirror-node.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ type MirrorNode interface {
GetLatestMessages(topicId hedera.TopicID, limit int64) ([]message.Message, error)
// GetMessagesForTopicBetween returns all topic messages for a given topic between timestamp `from` included and `to` excluded
GetMessagesForTopicBetween(topicId hedera.TopicID, from, to int64) ([]message.Message, error)
// GetNftTransactions returns the nft transactions for tokenID and serialNum
GetNftTransactions(tokenID string, serialNum int64) (transaction.NftTransactionsResponse, error)
// GetScheduledTransaction gets the Scheduled transaction of an executed transaction
GetScheduledTransaction(transactionID string) (*transaction.Response, error)
// GetTransaction gets all data related to a specific transaction id or returns an error
Expand All @@ -65,8 +63,6 @@ type MirrorNode interface {
// GetStateProof sends a query to get the state proof. If the query is successful, the function returns the state.
// If the query returns a status != 200, the function returns an error.
GetStateProof(transactionID string) ([]byte, error)
// GetNft retrieves an nft token entity by its id and serial number
GetNft(tokenID string, serialNum int64) (*transaction.Nft, error)
// AccountExists sends a query to check whether a specific account exists. If the query returns a status != 200, the function returns a false value
AccountExists(accountID hedera.AccountID) bool
// GetAccount gets the account data by ID.
Expand Down
4 changes: 0 additions & 4 deletions app/domain/client/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ type HederaNode interface {
SubmitScheduledTokenTransferTransaction(tokenID hedera.TokenID, transfers []transfer.Hedera, payerAccountID hedera.AccountID, memo string) (*hedera.TransactionResponse, error)
// SubmitScheduledHbarTransferTransaction creates an hbar transfer transaction and submits it as a scheduled transfer transaction
SubmitScheduledHbarTransferTransaction(transfers []transfer.Hedera, payerAccountID hedera.AccountID, memo string) (*hedera.TransactionResponse, error)
// SubmitScheduledNftTransferTransaction creates an Nft transfer transaction and submits it as a scheduled transfer transactions
SubmitScheduledNftTransferTransaction(nftID hedera.NftID, payerAccount hedera.AccountID, sender hedera.AccountID, receiving hedera.AccountID, memo string, approved bool) (*hedera.TransactionResponse, error)
// SubmitScheduledNftApproveTransaction creates an allowance of for the nft for the spender and submits it as a scheduled transaction
SubmitScheduledNftApproveTransaction(payer hedera.AccountID, memo string, nftId hedera.NftID, owner, spender hedera.AccountID) (*hedera.TransactionResponse, error)
// SubmitScheduleSign submits a ScheduleSign transaction for a given ScheduleID
SubmitScheduleSign(scheduleID hedera.ScheduleID) (*hedera.TransactionResponse, error)
// SubmitScheduledTokenMintTransaction creates a token mint transaction and submits it as a scheduled mint transaction
Expand Down
6 changes: 0 additions & 6 deletions app/domain/service/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
type Assets interface {
// FungibleNetworkAssets Gets all Fungible Assets by Network ID
FungibleNetworkAssets() map[uint64][]string
// NonFungibleNetworkAssets Gets all Non-Fungible Assets by Network ID
NonFungibleNetworkAssets() map[uint64][]string
// NativeToWrappedAssets Gets all Native assets with their Wrapped assets by Network ID
NativeToWrappedAssets() map[uint64]map[string]map[uint64]string
// WrappedFromNative Gets All Wrapped Assets for passed Native Asset's address
Expand All @@ -45,12 +43,8 @@ type Assets interface {
OppositeAsset(sourceChainId uint64, targetChainId uint64, assetAddress string) string
// FungibleAssetInfo Gets FungibleAssetInfo
FungibleAssetInfo(networkId uint64, assetAddress string) (assetInfo *assetModel.FungibleAssetInfo, exist bool)
// NonFungibleAssetInfo Gets NonFungibleAssetInfo
NonFungibleAssetInfo(networkId uint64, assetAddressOrId string) (assetInfo *assetModel.NonFungibleAssetInfo, exist bool)
// FetchHederaTokenReserveAmount Gets Hedera's Token Reserve Amount
FetchHederaTokenReserveAmount(assetId string, mirrorNode client.MirrorNode, isNative bool, hederaTokenBalances map[string]int) (reserveAmount *big.Int, err error)
// FetchEvmFungibleReserveAmount Gets EVM's Fungible Token Reserve Amount
FetchEvmFungibleReserveAmount(networkId uint64, assetAddress string, isNative bool, evmTokenClient client.EvmFungibleToken, routerContractAddress string) (inLowestDenomination *big.Int, err error)
// FetchEvmNonFungibleReserveAmount Gets EVM's Non-Fungible Token Reserve Amount
FetchEvmNonFungibleReserveAmount(networkId uint64, assetAddress string, isNative bool, evmTokenClient client.EvmNft, routerContractAddress string) (inLowestDenomination *big.Int, err error)
}
2 changes: 0 additions & 2 deletions app/domain/service/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ type Contracts interface {
ParseLockLog(log types.Log) (*abi.RouterLock, error)
// ParseUnlockLog parses a general typed log to a RouterUnlock event
ParseUnlockLog(log types.Log) (*abi.RouterUnlock, error)
// ParseBurnERC721Log parses a general typed log to a BurnERC721event
ParseBurnERC721Log(log types.Log) (*abi.RouterBurnERC721, error)
// WatchBurnEventLogs creates a subscription for Burn Events emitted in the Bridge contract
WatchBurnEventLogs(opts *bind.WatchOpts, sink chan<- *abi.RouterBurn) (event.Subscription, error)
// WatchLockEventLogs creates a subscription for Lock Events emitted in the Bridge contract
Expand Down
5 changes: 0 additions & 5 deletions app/domain/service/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ type Messages interface {
// SanityCheckFungibleSignature performs any validation required prior handling the topic message
// (verifies input data against the corresponding Transaction record)
SanityCheckFungibleSignature(tm *proto.TopicEthSignatureMessage) (bool, error)
// SanityCheckNftSignature performs any validation required prior handling the topic message
// (verifies input data against the corresponding Transaction record)
SanityCheckNftSignature(tm *proto.TopicEthNftSignatureMessage) (bool, error)
// ProcessSignature processes the signature message, verifying and updating all necessary fields in the DB
ProcessSignature(transferID, signature string, targetChainId uint64, timestamp int64, authMsg []byte) error
// SignFungibleMessage signs a Fungible message based on Transfer
SignFungibleMessage(transfer payload.Transfer) ([]byte, error)
// SignNftMessage signs an NFT messaged based on Transfer
SignNftMessage(transfer payload.Transfer) ([]byte, error)
}
6 changes: 0 additions & 6 deletions app/domain/service/pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,4 @@ type Pricing interface {
FetchAndUpdateUsdPrices() error
// GetMinAmountsForAPI getting all prices by networkId
GetMinAmountsForAPI() map[uint64]map[string]string
// GetHederaNftFee returns the nft fee for Hedera NFTs based on token id
GetHederaNftFee(token string) (int64, bool)
// GetHederaNftPrevFee returns the previous nft fee for Hedera NFTs based on token id
GetHederaNftPrevFee(token string) (int64, bool)

NftFees() map[uint64]map[string]pricing.NonFungibleFee
}
8 changes: 0 additions & 8 deletions app/domain/service/read-only.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,11 @@
package service

import (
"github.com/hashgraph/hedera-sdk-go/v2"
mirror_node "github.com/limechain/hedera-eth-bridge-validator/app/clients/hedera/mirror-node/model/transaction"
model "github.com/limechain/hedera-eth-bridge-validator/app/model/transfer"
"github.com/limechain/hedera-eth-bridge-validator/app/process/payload"
)

type ReadOnly interface {
FindTransfer(transferID string, fetch func() (*mirror_node.Response, error), save func(transactionID, scheduleID, status string) error)
FindAssetTransfer(transferID string, asset string, transfers []model.Hedera, fetch func() (*mirror_node.Response, error), save func(transactionID, scheduleID, status string) error)
FindNftTransfer(transferID string, tokenID string, serialNum int64, sender string, receiver string,
save func(transactionID, scheduleID, status string) error)
FindScheduledNftAllowanceApprove(
t *payload.Transfer,
sender hedera.AccountID,
save func(transactionID, scheduleID, status string) error)
}
7 changes: 0 additions & 7 deletions app/domain/service/scheduled.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package service

import (
"github.com/hashgraph/hedera-sdk-go/v2"
"github.com/limechain/hedera-eth-bridge-validator/app/model/transfer"
)

Expand All @@ -30,10 +29,4 @@ type Scheduled interface {
ExecuteScheduledMintTransaction(id, asset string, amount int64, status *chan string, onExecutionSuccess func(transactionID, scheduleID string), onExecutionFail, onSuccess, onFail func(transactionID string))
// ExecuteScheduledBurnTransaction submits a scheduled burn transaction and executes provided functions when necessary
ExecuteScheduledBurnTransaction(id, asset string, amount int64, status *chan string, onExecutionSuccess func(transactionID, scheduleID string), onExecutionFail, onSuccess, onFail func(transactionID string))
// ExecuteScheduledNftTransferTransaction submits a scheduled nft transfer transaction and executes provided functions when necessary
ExecuteScheduledNftTransferTransaction(id string, nftID hedera.NftID, sender hedera.AccountID, receiving hedera.AccountID, approved bool, onExecutionSuccess func(transactionID, scheduleID string), onExecutionFail, onSuccess, onFail func(transactionID string))
// ExecuteScheduledNftAllowTransaction submits a scheduled NFT allow transaction and executes provided functions when necessary
ExecuteScheduledNftAllowTransaction(
id string, nftID hedera.NftID, owner hedera.AccountID, spender hedera.AccountID,
onExecutionSuccess func(txId, scheduleId string), onExecutionFail, onSuccess, onFail func(txId string))
}
Loading
Loading