status-go/services/wallet/responses/router_transactions.go
Sale Djenic 28506bcd17 chore_: improvements of the sending route generated by the router process
This commit simplifies the sending process of the best route suggested by the router.
It also makes the sending process the same for accounts (key pairs) migrated to a keycard
and those stored locally in local keystore files.

Deprecated endpoints:
- `CreateMultiTransaction`
- `ProceedWithTransactionsSignatures`

Deprecated signal:
- `wallet.sign.transactions`

New endpoints:
- `BuildTransactionsFromRoute`
- `SendRouterTransactionsWithSignatures`

The flow for sending the best router suggested by the router:
- call `BuildTransactionsFromRoute`
- wait for the `wallet.router.sign-transactions` signal
- sign received hashes using `SignMessage` call or sign on keycard
- call `SendRouterTransactionsWithSignatures` with the signatures of signed hashes from the previous step
- `wallet.router.transactions-sent` signal will be sent after transactions are sent or if an error occurs

New signals:
- `wallet.router.sending-transactions-started` // notifies client that the sending transactions process started
- `wallet.router.sign-transactions` // notifies client about the list of transactions that need to be signed
- `wallet.router.transactions-sent` // notifies client about transactions that are sent
- `wallet.transaction.status-changed` // notifies about status of sent transactions
2024-10-01 14:30:33 +02:00

73 lines
2.5 KiB
Go

package responses
import (
"github.com/status-im/status-go/errors"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/transactions"
)
type SendDetails struct {
Uuid string `json:"uuid"`
SendType int `json:"sendType"`
FromAddress types.Address `json:"fromAddress"`
ToAddress types.Address `json:"toAddress"`
FromToken string `json:"fromToken"`
ToToken string `json:"toToken"`
FromAmount string `json:"fromAmount"` // total amount
ToAmount string `json:"toAmount"`
OwnerTokenBeingSent bool `json:"ownerTokenBeingSent"`
ErrorResponse *errors.ErrorResponse `json:"errorResponse,omitempty"`
Username string `json:"username"`
PublicKey string `json:"publicKey"`
PackID string `json:"packId"`
}
type SigningDetails struct {
Address types.Address `json:"address"`
AddressPath string `json:"addressPath"`
KeyUid string `json:"keyUid"`
SignOnKeycard bool `json:"signOnKeycard"`
Hashes []types.Hash `json:"hashes"`
}
type RouterTransactionsForSigning struct {
SendDetails *SendDetails `json:"sendDetails"`
SigningDetails *SigningDetails `json:"signingDetails"`
}
type RouterSentTransaction struct {
FromAddress types.Address `json:"fromAddress"`
ToAddress types.Address `json:"toAddress"`
FromChain uint64 `json:"fromChain"`
ToChain uint64 `json:"toChain"`
FromToken string `json:"fromToken"`
ToToken string `json:"toToken"`
Amount string `json:"amount"` // amount of the transaction
Hash types.Hash `json:"hash"`
ApprovalTx bool `json:"approvalTx"`
}
type RouterSentTransactions struct {
SendDetails *SendDetails `json:"sendDetails"`
SentTransactions []*RouterSentTransaction `json:"sentTransactions"`
}
func NewRouterSentTransaction(sendArgs *transactions.SendTxArgs, hash types.Hash, approvalTx bool) *RouterSentTransaction {
addr := types.Address{}
if sendArgs.To != nil {
addr = *sendArgs.To
}
return &RouterSentTransaction{
FromAddress: sendArgs.From,
ToAddress: addr,
FromChain: sendArgs.FromChainID,
ToChain: sendArgs.ToChainID,
FromToken: sendArgs.FromTokenID,
ToToken: sendArgs.ToTokenID,
Amount: sendArgs.Value.String(),
Hash: hash,
ApprovalTx: approvalTx,
}
}