2019-06-14 10:16:30 +00:00
package wallet
import (
"context"
2023-11-28 17:59:23 +00:00
"encoding/hex"
2023-08-01 18:50:30 +00:00
"encoding/json"
"errors"
2023-07-12 05:58:01 +00:00
"fmt"
2022-05-18 11:31:45 +00:00
"math/big"
"strings"
2022-11-15 12:14:41 +00:00
"time"
2019-06-14 10:16:30 +00:00
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
2023-07-12 05:58:01 +00:00
"github.com/ethereum/go-ethereum/ethclient"
2019-06-14 10:16:30 +00:00
"github.com/ethereum/go-ethereum/log"
2023-07-12 05:58:01 +00:00
gethrpc "github.com/ethereum/go-ethereum/rpc"
2022-05-18 11:31:45 +00:00
"github.com/status-im/status-go/eth-node/types"
2022-01-12 20:04:43 +00:00
"github.com/status-im/status-go/params"
2023-07-13 14:03:49 +00:00
"github.com/status-im/status-go/rpc/network"
2023-04-21 11:59:29 +00:00
"github.com/status-im/status-go/services/wallet/activity"
2022-09-13 07:10:59 +00:00
"github.com/status-im/status-go/services/wallet/bridge"
2023-11-01 19:09:10 +00:00
"github.com/status-im/status-go/services/wallet/collectibles"
2023-07-12 05:58:01 +00:00
wcommon "github.com/status-im/status-go/services/wallet/common"
2023-02-17 14:11:07 +00:00
"github.com/status-im/status-go/services/wallet/currency"
2022-11-15 12:14:41 +00:00
"github.com/status-im/status-go/services/wallet/history"
2023-01-25 18:28:51 +00:00
"github.com/status-im/status-go/services/wallet/thirdparty"
2022-09-13 07:10:59 +00:00
"github.com/status-im/status-go/services/wallet/token"
2021-09-09 14:28:54 +00:00
"github.com/status-im/status-go/services/wallet/transfer"
2023-11-26 15:50:12 +00:00
"github.com/status-im/status-go/services/wallet/walletconnect"
2023-10-30 16:58:57 +00:00
wc "github.com/status-im/status-go/services/wallet/walletconnect"
2023-08-01 18:50:30 +00:00
"github.com/status-im/status-go/services/wallet/walletevent"
2023-06-21 14:09:55 +00:00
"github.com/status-im/status-go/transactions"
2019-07-02 07:28:57 +00:00
)
2019-06-14 10:16:30 +00:00
func NewAPI ( s * Service ) * API {
2022-06-09 13:09:56 +00:00
router := NewRouter ( s )
2022-12-01 09:19:32 +00:00
return & API { s , s . reader , router }
2019-06-14 10:16:30 +00:00
}
// API is class with methods available over RPC.
type API struct {
2022-06-09 13:09:56 +00:00
s * Service
reader * Reader
router * Router
2022-05-10 07:48:05 +00:00
}
2022-12-01 09:19:32 +00:00
func ( api * API ) StartWallet ( ctx context . Context ) error {
return api . reader . Start ( )
2022-05-10 07:48:05 +00:00
}
2022-11-15 12:14:41 +00:00
func ( api * API ) StopWallet ( ctx context . Context ) error {
return api . s . Stop ( )
}
2023-09-12 12:45:32 +00:00
func ( api * API ) GetPairingsJSONFileContent ( ) ( [ ] byte , error ) {
return api . s . keycardPairings . GetPairingsJSONFileContent ( )
}
func ( api * API ) SetPairingsJSONFileContent ( content [ ] byte ) error {
return api . s . keycardPairings . SetPairingsJSONFileContent ( content )
}
2022-12-02 10:55:44 +00:00
func ( api * API ) GetWalletToken ( ctx context . Context , addresses [ ] common . Address ) ( map [ common . Address ] [ ] Token , error ) {
return api . reader . GetWalletToken ( ctx , addresses )
2019-06-14 10:16:30 +00:00
}
2023-04-25 12:00:17 +00:00
func ( api * API ) GetCachedWalletTokensWithoutMarketData ( ctx context . Context ) ( map [ common . Address ] [ ] Token , error ) {
return api . reader . GetCachedWalletTokensWithoutMarketData ( )
}
2022-05-18 11:31:45 +00:00
type DerivedAddress struct {
Address common . Address ` json:"address" `
2023-05-16 10:48:00 +00:00
PublicKey types . HexBytes ` json:"public-key,omitempty" `
2022-05-18 11:31:45 +00:00
Path string ` json:"path" `
HasActivity bool ` json:"hasActivity" `
AlreadyCreated bool ` json:"alreadyCreated" `
}
2023-09-07 08:23:59 +00:00
// @deprecated
2021-09-09 14:28:54 +00:00
func ( api * API ) CheckRecentHistory ( ctx context . Context , addresses [ ] common . Address ) error {
2021-09-22 17:49:20 +00:00
return api . s . transferController . CheckRecentHistory ( [ ] uint64 { api . s . rpcClient . UpstreamChainID } , addresses )
2021-09-09 14:28:54 +00:00
}
2023-09-07 08:23:59 +00:00
// @deprecated
2021-09-09 14:28:54 +00:00
func ( api * API ) CheckRecentHistoryForChainIDs ( ctx context . Context , chainIDs [ ] uint64 , addresses [ ] common . Address ) error {
return api . s . transferController . CheckRecentHistory ( chainIDs , addresses )
2021-02-11 15:20:06 +00:00
}
2022-10-18 13:27:44 +00:00
func hexBigToBN ( hexBig * hexutil . Big ) * big . Int {
var bN * big . Int
if hexBig != nil {
bN = hexBig . ToInt ( )
}
return bN
}
2023-09-07 08:23:59 +00:00
// @deprecated
2020-02-07 10:26:00 +00:00
// GetTransfersByAddress returns transfers for a single address
2021-09-09 14:28:54 +00:00
func ( api * API ) GetTransfersByAddress ( ctx context . Context , address common . Address , toBlock , limit * hexutil . Big , fetchMore bool ) ( [ ] transfer . View , error ) {
2021-11-24 12:59:45 +00:00
log . Debug ( "[WalletAPI:: GetTransfersByAddress] get transfers for an address" , "address" , address )
2022-10-18 13:27:44 +00:00
var intLimit = int64 ( 1 )
if limit != nil {
intLimit = limit . ToInt ( ) . Int64 ( )
}
return api . s . transferController . GetTransfersByAddress ( ctx , api . s . rpcClient . UpstreamChainID , address , hexBigToBN ( toBlock ) , intLimit , fetchMore )
2021-09-09 14:28:54 +00:00
}
status-im/status-react#9203 Faster tx fetching with less request
*** How it worked before this PR on multiaccount creation:
- On multiacc creation we scanned chain for eth and erc20 transfers. For
each address of a new empty multiaccount this scan required
1. two `eth_getBalance` requests to find out that there is no any
balance change between zero and the last block, for eth transfers
2. and `chain-size/100000` (currently ~100) `eth_getLogs` requests,
for erc20 transfers
- For some reason we scanned an address of the chat account as well, and
also accounts were not deduplicated. So even for an empty multiacc we
scanned chain twice for each chat and main wallet addresses, in result
app had to execute about 400 requests.
- As mentioned above, `eth_getBalance` requests were used to check if
there were any eth transfers, and that caused empty history in case
if user already used all available eth (so that both zero and latest
blocks show 0 eth for an address). There might have been transactions
but we wouldn't fetch/show them.
- There was no upper limit for the number of rpc requests during the
scan, so it could require indefinite number of requests; the scanning
algorithm was written so that we persisted the whole history of
transactions or tried to scan form the beginning again in case of
failure, giving up only after 10 minutes of failures. In result
addresses with sufficient number of transactions would never be fully
scanned and during these 10 minutes app could use gigabytes of
internet data.
- Failures were caused by `eth_getBlockByNumber`/`eth_getBlockByHash`
requests. These requests return significantly bigger responses than
`eth_getBalance`/`eth_transactionsCount` and it is likely that
execution of thousands of them in parallel caused failures for
accounts with hundreds of transactions. Even for an account with 12k
we could successfully determine blocks with transaction in a few
minutes using `eth_getBalance` requests, but `eth_getBlock...`
couldn't be processed for this acc.
- There was no caching for for `eth_getBalance` requests, and this
caused in average 3-4 times more such requests than is needed.
*** How it works now on multiaccount creation:
- On multiacc creation we scan chain for last ~30 eth transactions and
then check erc20 in the range where these eth transactions were found.
For an empty address in multiacc this means:
1. two `eth_getBalance` transactions to determine that there was no
balance change between zero and the last block; two
`eth_transactionsCount` requests to determine there are no outgoing
transactions for this address; total 4 requests for eth transfers
2. 20 `eth_getLogs` for erc20 transfers. This number can be lowered,
but that's not a big deal
- Deduplication of addresses is added and also we don't scan chat
account, so a new multiacc requires ~25 (we also request latest block
number and probably execute a few other calls) request to determine
that multiacc is empty (comparing to ~400 before)
- In case if address contains transactions we:
1. determine the range which contains 20-25 outgoing eth/erc20
transactions. This usually requires up to 10 `eth_transactionCount`
requests
2. then we scan chain for eth transfers using `eth_getBalance` and
`eth_transactionCount` (for double checking zero balances)
3. we make sure that we do not scan db for more than 30 blocks with
transfers. That's important for accounts with mostly incoming
transactions, because the range found on the first step might
contain any number of incoming transfers, but only 20-25 outgoing
transactions
4. when we found ~30 blocks in a given range, we update initial
range `from` block using the oldest found block
5. and now we scan db for erc20transfers using `eth_getLogs`
`oldest-found-eth-block`-`latest-block`, we make not more than 20 calls
6. when all blocks which contain incoming/outgoing transfers for a
given address are found, we save these blocks to db and mark that
transfers from these blocks are still to be fetched
7. Then we select latest ~30 (the number can be adjusted) blocks from
these which were found and fetch transfers, this requires 3-4
requests per transfer.
8. we persist scanned range so that we know were to start next time
9. we dispatch an event which tells client that transactions are found
10. client fetches latest 20 transfers
- when user presses "fetch more" button we check if app's db contains next
20 transfers, if not we scan chain again and return transfers after
small fixes
2019-12-18 11:01:46 +00:00
2023-09-07 08:23:59 +00:00
// @deprecated
2021-11-24 12:59:45 +00:00
// LoadTransferByHash loads transfer to the database
2023-06-02 20:08:45 +00:00
// Only used by status-mobile
2021-11-24 12:59:45 +00:00
func ( api * API ) LoadTransferByHash ( ctx context . Context , address common . Address , hash common . Hash ) error {
log . Debug ( "[WalletAPI:: LoadTransferByHash] get transfer by hash" , "address" , address , "hash" , hash )
return api . s . transferController . LoadTransferByHash ( ctx , api . s . rpcClient , address , hash )
}
2023-09-07 08:23:59 +00:00
// @deprecated
2021-09-09 14:28:54 +00:00
func ( api * API ) GetTransfersByAddressAndChainID ( ctx context . Context , chainID uint64 , address common . Address , toBlock , limit * hexutil . Big , fetchMore bool ) ( [ ] transfer . View , error ) {
2022-07-04 07:48:30 +00:00
log . Debug ( "[WalletAPI:: GetTransfersByAddressAndChainIDs] get transfers for an address" , "address" , address )
2022-10-18 13:27:44 +00:00
return api . s . transferController . GetTransfersByAddress ( ctx , chainID , address , hexBigToBN ( toBlock ) , limit . ToInt ( ) . Int64 ( ) , fetchMore )
2021-09-09 14:28:54 +00:00
}
2023-09-07 08:23:59 +00:00
// @deprecated
2023-04-21 11:59:29 +00:00
func ( api * API ) GetTransfersForIdentities ( ctx context . Context , identities [ ] transfer . TransactionIdentity ) ( [ ] transfer . View , error ) {
2023-06-13 09:25:23 +00:00
log . Debug ( "wallet.api.GetTransfersForIdentities" , "identities.len" , len ( identities ) )
2023-04-21 11:59:29 +00:00
return api . s . transferController . GetTransfersForIdentities ( ctx , identities )
}
2023-05-25 13:12:54 +00:00
func ( api * API ) FetchDecodedTxData ( ctx context . Context , data string ) ( * thirdparty . DataParsed , error ) {
log . Debug ( "[Wallet: FetchDecodedTxData]" )
2023-07-06 07:37:04 +00:00
return api . s . decoder . Decode ( data )
2023-05-25 13:12:54 +00:00
}
2022-11-15 12:14:41 +00:00
// GetBalanceHistory retrieves token balance history for token identity on multiple chains
2023-11-29 11:20:18 +00:00
func ( api * API ) GetBalanceHistory ( ctx context . Context , chainIDs [ ] uint64 , addresses [ ] common . Address , tokenSymbol string , currencySymbol string , timeInterval history . TimeInterval ) ( [ ] * history . ValuePoint , error ) {
log . Debug ( "wallet.api.GetBalanceHistory" , "chainIDs" , chainIDs , "address" , addresses , "tokenSymbol" , tokenSymbol , "currencySymbol" , currencySymbol , "timeInterval" , timeInterval )
2023-10-04 12:00:12 +00:00
var fromTimestamp uint64
now := uint64 ( time . Now ( ) . UTC ( ) . Unix ( ) )
switch timeInterval {
case history . BalanceHistoryAllTime :
fromTimestamp = 0
case history . BalanceHistory1Year :
fallthrough
case history . BalanceHistory6Months :
fallthrough
case history . BalanceHistory1Month :
fallthrough
case history . BalanceHistory7Days :
fromTimestamp = now - history . TimeIntervalDurationSecs ( timeInterval )
default :
return nil , fmt . Errorf ( "unknown time interval: %v" , timeInterval )
}
2023-11-29 11:20:18 +00:00
return api . GetBalanceHistoryRange ( ctx , chainIDs , addresses , tokenSymbol , currencySymbol , fromTimestamp , now )
2023-10-04 12:00:12 +00:00
}
// GetBalanceHistoryRange retrieves token balance history for token identity on multiple chains for a time range
// 'toTimestamp' is ignored for now, but will be used in the future to limit the range of the history
2023-11-29 11:20:18 +00:00
func ( api * API ) GetBalanceHistoryRange ( ctx context . Context , chainIDs [ ] uint64 , addresses [ ] common . Address , tokenSymbol string , currencySymbol string , fromTimestamp uint64 , _ uint64 ) ( [ ] * history . ValuePoint , error ) {
log . Debug ( "wallet.api.GetBalanceHistoryRange" , "chainIDs" , chainIDs , "address" , addresses , "tokenSymbol" , tokenSymbol , "currencySymbol" , currencySymbol , "fromTimestamp" , fromTimestamp )
return api . s . history . GetBalanceHistory ( ctx , chainIDs , addresses , tokenSymbol , currencySymbol , fromTimestamp )
2022-10-18 13:27:44 +00:00
}
2023-10-17 15:05:05 +00:00
func ( api * API ) GetTokenList ( ctx context . Context ) ( [ ] * token . List , error ) {
log . Debug ( "call to get token list" )
rst := api . s . tokenManager . GetList ( )
log . Debug ( "result from token list" , "len" , len ( rst ) )
return rst , nil
}
// @deprecated
2022-09-13 07:10:59 +00:00
func ( api * API ) GetTokens ( ctx context . Context , chainID uint64 ) ( [ ] * token . Token , error ) {
2022-01-14 09:21:00 +00:00
log . Debug ( "call to get tokens" )
2023-10-17 15:05:05 +00:00
rst , err := api . s . tokenManager . GetTokens ( chainID )
2022-01-14 09:21:00 +00:00
log . Debug ( "result from token store" , "len" , len ( rst ) )
return rst , err
}
2023-10-17 15:05:05 +00:00
// @deprecated
2022-09-13 07:10:59 +00:00
func ( api * API ) GetCustomTokens ( ctx context . Context ) ( [ ] * token . Token , error ) {
2019-12-10 17:31:08 +00:00
log . Debug ( "call to get custom tokens" )
2023-10-17 15:05:05 +00:00
rst , err := api . s . tokenManager . GetCustoms ( true )
2019-12-10 17:31:08 +00:00
log . Debug ( "result from database for custom tokens" , "len" , len ( rst ) )
return rst , err
}
2022-09-13 07:10:59 +00:00
func ( api * API ) DiscoverToken ( ctx context . Context , chainID uint64 , address common . Address ) ( * token . Token , error ) {
2022-04-04 16:54:44 +00:00
log . Debug ( "call to get discover token" )
2022-09-13 07:10:59 +00:00
token , err := api . s . tokenManager . DiscoverToken ( ctx , chainID , address )
2022-04-04 16:54:44 +00:00
return token , err
}
2022-09-13 07:10:59 +00:00
func ( api * API ) AddCustomToken ( ctx context . Context , token token . Token ) error {
2019-12-10 17:31:08 +00:00
log . Debug ( "call to create or edit custom token" )
2021-09-09 14:28:54 +00:00
if token . ChainID == 0 {
2021-09-22 17:49:20 +00:00
token . ChainID = api . s . rpcClient . UpstreamChainID
2021-09-09 14:28:54 +00:00
}
2022-09-13 07:10:59 +00:00
err := api . s . tokenManager . UpsertCustom ( token )
2019-12-10 17:31:08 +00:00
log . Debug ( "result from database for create or edit custom token" , "err" , err )
return err
}
2023-09-07 08:23:59 +00:00
// @deprecated
2019-12-10 17:31:08 +00:00
func ( api * API ) DeleteCustomToken ( ctx context . Context , address common . Address ) error {
log . Debug ( "call to remove custom token" )
2022-09-13 07:10:59 +00:00
err := api . s . tokenManager . DeleteCustom ( api . s . rpcClient . UpstreamChainID , address )
2021-09-09 14:28:54 +00:00
log . Debug ( "result from database for remove custom token" , "err" , err )
return err
}
func ( api * API ) DeleteCustomTokenByChainID ( ctx context . Context , chainID uint64 , address common . Address ) error {
log . Debug ( "call to remove custom token" )
2022-09-13 07:10:59 +00:00
err := api . s . tokenManager . DeleteCustom ( chainID , address )
2019-12-10 17:31:08 +00:00
log . Debug ( "result from database for remove custom token" , "err" , err )
return err
}
2020-09-14 13:39:24 +00:00
2022-05-10 07:48:05 +00:00
func ( api * API ) GetSavedAddresses ( ctx context . Context ) ( [ ] SavedAddress , error ) {
2021-09-10 18:08:22 +00:00
log . Debug ( "call to get saved addresses" )
2023-03-06 13:26:46 +00:00
rst , err := api . s . savedAddressesManager . GetSavedAddresses ( )
2021-09-10 18:08:22 +00:00
log . Debug ( "result from database for saved addresses" , "len" , len ( rst ) )
return rst , err
}
func ( api * API ) AddSavedAddress ( ctx context . Context , sa SavedAddress ) error {
log . Debug ( "call to create or edit saved address" )
2022-09-14 10:46:11 +00:00
_ , err := api . s . savedAddressesManager . UpdateMetadataAndUpsertSavedAddress ( sa )
2021-09-10 18:08:22 +00:00
log . Debug ( "result from database for create or edit saved address" , "err" , err )
return err
}
2023-03-06 13:26:46 +00:00
func ( api * API ) DeleteSavedAddress ( ctx context . Context , address common . Address , ens string , isTest bool ) error {
2021-09-10 18:08:22 +00:00
log . Debug ( "call to remove saved address" )
2023-03-06 13:26:46 +00:00
_ , err := api . s . savedAddressesManager . DeleteSavedAddress ( address , ens , isTest , uint64 ( time . Now ( ) . Unix ( ) ) )
2021-09-10 18:08:22 +00:00
log . Debug ( "result from database for remove saved address" , "err" , err )
return err
}
2023-09-07 08:23:59 +00:00
// @deprecated
2023-06-21 14:09:55 +00:00
func ( api * API ) GetPendingTransactions ( ctx context . Context ) ( [ ] * transactions . PendingTransaction , error ) {
2023-08-01 18:50:30 +00:00
log . Debug ( "wallet.api.GetPendingTransactions" )
rst , err := api . s . pendingTxManager . GetAllPending ( )
log . Debug ( "wallet.api.GetPendingTransactions RESULT" , "len" , len ( rst ) )
2020-09-14 13:39:24 +00:00
return rst , err
}
2023-06-21 14:09:55 +00:00
func ( api * API ) GetPendingTransactionsForIdentities ( ctx context . Context , identities [ ] transfer . TransactionIdentity ) (
result [ ] * transactions . PendingTransaction , err error ) {
2023-08-01 18:50:30 +00:00
log . Debug ( "wallet.api.GetPendingTransactionsForIdentities" )
2023-04-21 11:59:29 +00:00
2023-06-21 14:09:55 +00:00
result = make ( [ ] * transactions . PendingTransaction , 0 , len ( identities ) )
var pt * transactions . PendingTransaction
2023-04-21 11:59:29 +00:00
for _ , identity := range identities {
2023-08-01 18:50:30 +00:00
pt , err = api . s . pendingTxManager . GetPendingEntry ( identity . ChainID , identity . Hash )
2023-04-21 11:59:29 +00:00
result = append ( result , pt )
}
2023-08-01 18:50:30 +00:00
log . Debug ( "wallet.api.GetPendingTransactionsForIdentities RES" , "len" , len ( result ) )
2023-04-21 11:59:29 +00:00
return
}
2023-09-07 08:23:59 +00:00
// @deprecated
2023-08-01 18:50:30 +00:00
// TODO - #11861: Remove this and replace with EventPendingTransactionStatusChanged event and Delete to confirm the transaction where it is needed
func ( api * API ) WatchTransactionByChainID ( ctx context . Context , chainID uint64 , transactionHash common . Hash ) ( err error ) {
log . Debug ( "wallet.api.WatchTransactionByChainID" , "chainID" , chainID , "transactionHash" , transactionHash )
var status * transactions . TxStatus
2023-08-30 16:14:57 +00:00
defer func ( ) {
log . Debug ( "wallet.api.WatchTransactionByChainID return" , "err" , err , "chainID" , chainID , "transactionHash" , transactionHash )
} ( )
2023-06-21 14:09:55 +00:00
2023-08-01 18:50:30 +00:00
// Workaround to keep the blocking call until the clients use the PendingTxTracker APIs
eventChan := make ( chan walletevent . Event , 2 )
sub := api . s . feed . Subscribe ( eventChan )
defer sub . Unsubscribe ( )
2020-09-14 13:39:24 +00:00
2023-08-01 18:50:30 +00:00
status , err = api . s . pendingTxManager . Watch ( ctx , wcommon . ChainID ( chainID ) , transactionHash )
if err == nil && * status != transactions . Pending {
return nil
2021-03-18 15:14:00 +00:00
}
2021-04-01 09:04:47 +00:00
2023-08-01 18:50:30 +00:00
for {
select {
case we := <- eventChan :
if transactions . EventPendingTransactionStatusChanged == we . Type {
var p transactions . StatusChangedPayload
err = json . Unmarshal ( [ ] byte ( we . Message ) , & p )
if err != nil {
return err
}
if p . ChainID == wcommon . ChainID ( chainID ) && p . Hash == transactionHash {
return nil
}
}
case <- time . After ( 10 * time . Minute ) :
return errors . New ( "timeout watching for pending transaction" )
}
2021-04-01 09:04:47 +00:00
}
2021-09-09 14:28:54 +00:00
}
2021-05-20 12:11:18 +00:00
2021-09-09 14:28:54 +00:00
func ( api * API ) GetCryptoOnRamps ( ctx context . Context ) ( [ ] CryptoOnRamp , error ) {
return api . s . cryptoOnRampManager . Get ( )
2021-05-20 12:11:18 +00:00
}
2021-08-20 19:53:24 +00:00
2023-07-18 15:01:53 +00:00
/ *
Collectibles API Start
* /
2023-11-14 17:16:39 +00:00
func ( api * API ) FetchBalancesByOwnerAndContractAddress ( ctx context . Context , chainID wcommon . ChainID , ownerAddress common . Address , contractAddresses [ ] common . Address ) ( thirdparty . TokenBalancesPerContractAddress , error ) {
2023-07-18 15:01:53 +00:00
log . Debug ( "call to FetchBalancesByOwnerAndContractAddress" )
2023-07-18 15:02:56 +00:00
2023-11-14 17:16:39 +00:00
return api . s . collectiblesManager . FetchBalancesByOwnerAndContractAddress ( ctx , chainID , ownerAddress , contractAddresses )
2023-07-18 15:01:53 +00:00
}
2023-09-21 21:42:02 +00:00
func ( api * API ) RefetchOwnedCollectibles ( ) error {
log . Debug ( "wallet.api.RefetchOwnedCollectibles" )
api . s . collectibles . RefetchOwnedCollectibles ( )
return nil
}
2023-11-06 12:58:36 +00:00
func ( api * API ) GetOwnedCollectiblesAsync ( requestID int32 , chainIDs [ ] wcommon . ChainID , addresses [ ] common . Address , filter collectibles . Filter , offset int , limit int , dataType collectibles . CollectibleDataType , fetchCriteria collectibles . FetchCriteria ) error {
log . Debug ( "wallet.api.GetOwnedCollectiblesAsync" , "requestID" , requestID , "chainIDs.count" , len ( chainIDs ) , "addr.count" , len ( addresses ) , "offset" , offset , "limit" , limit , "dataType" , dataType , "fetchCriteria" , fetchCriteria )
2023-07-18 15:02:56 +00:00
2023-11-06 12:58:36 +00:00
api . s . collectibles . GetOwnedCollectiblesAsync ( requestID , chainIDs , addresses , filter , offset , limit , dataType , fetchCriteria )
2023-07-18 15:02:56 +00:00
return nil
}
2023-11-02 23:33:50 +00:00
func ( api * API ) GetCollectiblesByUniqueIDAsync ( requestID int32 , uniqueIDs [ ] thirdparty . CollectibleUniqueID , dataType collectibles . CollectibleDataType ) error {
log . Debug ( "wallet.api.GetCollectiblesByUniqueIDAsync" , "requestID" , requestID , "uniqueIDs.count" , len ( uniqueIDs ) , "dataType" , dataType )
2023-07-18 15:02:56 +00:00
2023-11-02 23:33:50 +00:00
api . s . collectibles . GetCollectiblesByUniqueIDAsync ( requestID , uniqueIDs , dataType )
2023-07-18 15:02:56 +00:00
return nil
}
2023-09-07 08:23:59 +00:00
// @deprecated
2023-07-31 19:41:14 +00:00
func ( api * API ) GetCollectiblesByOwnerWithCursor ( ctx context . Context , chainID wcommon . ChainID , owner common . Address , cursor string , limit int ) ( * thirdparty . FullCollectibleDataContainer , error ) {
2023-07-18 15:01:53 +00:00
log . Debug ( "call to GetCollectiblesByOwnerWithCursor" )
2023-11-14 17:16:39 +00:00
return api . s . collectiblesManager . FetchAllAssetsByOwner ( ctx , chainID , owner , cursor , limit , thirdparty . FetchFromAnyProvider )
2021-08-20 19:53:24 +00:00
}
2021-09-09 14:28:54 +00:00
2023-09-07 08:23:59 +00:00
// @deprecated
2023-07-31 19:41:14 +00:00
func ( api * API ) GetCollectiblesByOwnerAndContractAddressWithCursor ( ctx context . Context , chainID wcommon . ChainID , owner common . Address , contractAddresses [ ] common . Address , cursor string , limit int ) ( * thirdparty . FullCollectibleDataContainer , error ) {
2023-07-18 15:01:53 +00:00
log . Debug ( "call to GetCollectiblesByOwnerAndContractAddressWithCursor" )
2023-11-14 17:16:39 +00:00
return api . s . collectiblesManager . FetchAllAssetsByOwnerAndContractAddress ( ctx , chainID , owner , contractAddresses , cursor , limit , thirdparty . FetchFromAnyProvider )
2023-03-17 21:20:31 +00:00
}
2023-09-07 08:23:59 +00:00
// @deprecated
2023-07-31 19:41:14 +00:00
func ( api * API ) GetCollectiblesByUniqueID ( ctx context . Context , uniqueIDs [ ] thirdparty . CollectibleUniqueID ) ( [ ] thirdparty . FullCollectibleData , error ) {
2023-07-18 15:01:53 +00:00
log . Debug ( "call to GetCollectiblesByUniqueID" )
2023-11-14 17:16:39 +00:00
return api . s . collectiblesManager . FetchAssetsByCollectibleUniqueID ( ctx , uniqueIDs )
2023-02-28 03:10:38 +00:00
}
2023-11-14 17:16:39 +00:00
func ( api * API ) GetCollectibleOwnersByContractAddress ( ctx context . Context , chainID wcommon . ChainID , contractAddress common . Address ) ( * thirdparty . CollectibleContractOwnership , error ) {
2023-04-17 11:42:01 +00:00
log . Debug ( "call to GetCollectibleOwnersByContractAddress" )
2023-11-14 17:16:39 +00:00
return api . s . collectiblesManager . FetchCollectibleOwnersByContractAddress ( ctx , chainID , contractAddress )
2023-04-17 11:42:01 +00:00
}
2023-07-18 15:01:53 +00:00
/ *
Collectibles API End
* /
2023-07-13 17:26:17 +00:00
2022-01-12 20:04:43 +00:00
func ( api * API ) AddEthereumChain ( ctx context . Context , network params . Network ) error {
2021-09-09 14:28:54 +00:00
log . Debug ( "call to AddEthereumChain" )
2021-09-22 17:49:20 +00:00
return api . s . rpcClient . NetworkManager . Upsert ( & network )
2021-09-09 14:28:54 +00:00
}
func ( api * API ) DeleteEthereumChain ( ctx context . Context , chainID uint64 ) error {
log . Debug ( "call to DeleteEthereumChain" )
2021-09-22 17:49:20 +00:00
return api . s . rpcClient . NetworkManager . Delete ( chainID )
2021-09-09 14:28:54 +00:00
}
2023-07-13 14:03:49 +00:00
func ( api * API ) GetEthereumChains ( ctx context . Context ) ( [ ] * network . CombinedNetwork , error ) {
2021-09-09 14:28:54 +00:00
log . Debug ( "call to GetEthereumChains" )
2023-07-13 14:03:49 +00:00
return api . s . rpcClient . NetworkManager . GetCombinedNetworks ( )
2021-09-09 14:28:54 +00:00
}
2022-03-23 08:35:58 +00:00
2023-09-07 08:23:59 +00:00
// @deprecated
2023-01-12 17:54:14 +00:00
func ( api * API ) FetchPrices ( ctx context . Context , symbols [ ] string , currencies [ ] string ) ( map [ string ] map [ string ] float64 , error ) {
2022-03-23 08:35:58 +00:00
log . Debug ( "call to FetchPrices" )
2023-02-21 09:05:16 +00:00
return api . s . marketManager . FetchPrices ( symbols , currencies )
2023-01-19 14:49:48 +00:00
}
2023-09-07 08:23:59 +00:00
// @deprecated
2023-02-21 09:05:16 +00:00
func ( api * API ) FetchMarketValues ( ctx context . Context , symbols [ ] string , currency string ) ( map [ string ] thirdparty . TokenMarketValues , error ) {
2022-08-23 08:46:15 +00:00
log . Debug ( "call to FetchMarketValues" )
2023-02-21 09:05:16 +00:00
return api . s . marketManager . FetchTokenMarketValues ( symbols , currency )
2022-08-23 08:46:15 +00:00
}
2023-02-21 09:05:16 +00:00
func ( api * API ) GetHourlyMarketValues ( ctx context . Context , symbol string , currency string , limit int , aggregate int ) ( [ ] thirdparty . HistoricalPrice , error ) {
2022-10-10 19:02:04 +00:00
log . Debug ( "call to GetHourlyMarketValues" )
2023-02-21 09:05:16 +00:00
return api . s . marketManager . FetchHistoricalHourlyPrices ( symbol , currency , limit , aggregate )
2022-10-10 19:02:04 +00:00
}
2023-02-21 09:05:16 +00:00
func ( api * API ) GetDailyMarketValues ( ctx context . Context , symbol string , currency string , limit int , allData bool , aggregate int ) ( [ ] thirdparty . HistoricalPrice , error ) {
2022-10-10 19:02:04 +00:00
log . Debug ( "call to GetDailyMarketValues" )
2023-02-21 09:05:16 +00:00
return api . s . marketManager . FetchHistoricalDailyPrices ( symbol , currency , limit , allData , aggregate )
2022-10-10 19:02:04 +00:00
}
2023-09-07 08:23:59 +00:00
// @deprecated
2023-02-21 09:05:16 +00:00
func ( api * API ) FetchTokenDetails ( ctx context . Context , symbols [ ] string ) ( map [ string ] thirdparty . TokenDetails , error ) {
2022-08-23 08:46:15 +00:00
log . Debug ( "call to FetchTokenDetails" )
2023-02-21 09:05:16 +00:00
return api . s . marketManager . FetchTokenDetails ( symbols )
2022-08-23 08:46:15 +00:00
}
2022-03-29 21:12:05 +00:00
func ( api * API ) GetSuggestedFees ( ctx context . Context , chainID uint64 ) ( * SuggestedFees , error ) {
log . Debug ( "call to GetSuggestedFees" )
return api . s . feesManager . suggestedFees ( ctx , chainID )
}
2022-05-18 11:31:45 +00:00
2023-09-04 10:18:46 +00:00
func ( api * API ) GetEstimatedLatestBlockNumber ( ctx context . Context , chainID uint64 ) ( uint64 , error ) {
log . Debug ( "call to GetEstimatedLatestBlockNumber, chainID:" , chainID )
return api . s . blockChainState . GetEstimatedLatestBlockNumber ( ctx , chainID )
}
2023-09-07 08:23:59 +00:00
// @deprecated
2022-09-13 07:10:59 +00:00
func ( api * API ) GetTransactionEstimatedTime ( ctx context . Context , chainID uint64 , maxFeePerGas * big . Float ) ( TransactionEstimation , error ) {
2022-07-12 12:25:32 +00:00
log . Debug ( "call to getTransactionEstimatedTime" )
return api . s . feesManager . transactionEstimatedTime ( ctx , chainID , maxFeePerGas ) , nil
}
2022-11-23 17:49:23 +00:00
func ( api * API ) GetSuggestedRoutes (
ctx context . Context ,
sendType SendType ,
2023-11-02 11:35:28 +00:00
addrFrom common . Address ,
addrTo common . Address ,
2022-11-23 17:49:23 +00:00
amountIn * hexutil . Big ,
2023-08-24 08:45:14 +00:00
tokenID string ,
2022-11-23 17:49:23 +00:00
disabledFromChainIDs ,
disabledToChaindIDs ,
preferedChainIDs [ ] uint64 ,
gasFeeMode GasFeeMode ,
fromLockedAmount map [ uint64 ] * hexutil . Big ,
) ( * SuggestedRoutes , error ) {
2022-06-09 13:09:56 +00:00
log . Debug ( "call to GetSuggestedRoutes" )
2023-11-02 11:35:28 +00:00
return api . router . suggestedRoutes ( ctx , sendType , addrFrom , addrTo , amountIn . ToInt ( ) , tokenID , disabledFromChainIDs ,
disabledToChaindIDs , preferedChainIDs , gasFeeMode , fromLockedAmount )
2022-06-09 13:09:56 +00:00
}
2023-03-20 07:39:33 +00:00
// Generates addresses for the provided paths, response doesn't include `HasActivity` value (if you need it check `GetAddressDetails` function)
func ( api * API ) GetDerivedAddresses ( ctx context . Context , password string , derivedFrom string , paths [ ] string ) ( [ ] * DerivedAddress , error ) {
2023-01-31 12:16:05 +00:00
info , err := api . s . gethManager . AccountsGenerator ( ) . LoadAccount ( derivedFrom , password )
if err != nil {
return nil , err
}
2023-03-20 07:39:33 +00:00
return api . getDerivedAddresses ( info . ID , paths )
2023-01-31 12:16:05 +00:00
}
2023-03-20 07:39:33 +00:00
// Generates addresses for the provided paths derived from the provided mnemonic, response doesn't include `HasActivity` value (if you need it check `GetAddressDetails` function)
func ( api * API ) GetDerivedAddressesForMnemonic ( ctx context . Context , mnemonic string , paths [ ] string ) ( [ ] * DerivedAddress , error ) {
2022-05-18 11:31:45 +00:00
mnemonicNoExtraSpaces := strings . Join ( strings . Fields ( mnemonic ) , " " )
info , err := api . s . gethManager . AccountsGenerator ( ) . ImportMnemonic ( mnemonicNoExtraSpaces , "" )
if err != nil {
return nil , err
}
2023-03-20 07:39:33 +00:00
return api . getDerivedAddresses ( info . ID , paths )
2022-05-18 11:31:45 +00:00
}
2023-03-20 07:39:33 +00:00
// Generates addresses for the provided paths, response doesn't include `HasActivity` value (if you need it check `GetAddressDetails` function)
func ( api * API ) getDerivedAddresses ( id string , paths [ ] string ) ( [ ] * DerivedAddress , error ) {
2023-07-25 15:17:17 +00:00
addedAccounts , err := api . s . accountsDB . GetActiveAccounts ( )
2022-05-18 11:31:45 +00:00
if err != nil {
2023-03-20 07:39:33 +00:00
return nil , err
2022-05-18 11:31:45 +00:00
}
2023-03-20 07:39:33 +00:00
info , err := api . s . gethManager . AccountsGenerator ( ) . DeriveAddresses ( id , paths )
2022-05-18 11:31:45 +00:00
if err != nil {
2023-03-20 07:39:33 +00:00
return nil , err
2022-05-18 11:31:45 +00:00
}
2022-10-21 08:01:31 +00:00
2023-03-20 07:39:33 +00:00
derivedAddresses := make ( [ ] * DerivedAddress , 0 )
for accPath , acc := range info {
derivedAddress := & DerivedAddress {
2023-05-16 10:48:00 +00:00
Address : common . HexToAddress ( acc . Address ) ,
PublicKey : types . Hex2Bytes ( acc . PublicKey ) ,
Path : accPath ,
2023-03-20 07:39:33 +00:00
}
for _ , account := range addedAccounts {
if types . Address ( derivedAddress . Address ) == account . Address {
derivedAddress . AlreadyCreated = true
break
}
}
derivedAddresses = append ( derivedAddresses , derivedAddress )
}
2022-10-21 08:01:31 +00:00
return derivedAddresses , nil
}
2023-05-25 09:53:15 +00:00
func ( api * API ) AddressExists ( ctx context . Context , address types . Address ) ( bool , error ) {
return api . s . accountsDB . AddressExists ( address )
}
2023-03-20 07:39:33 +00:00
// Returns details for the passed address (response doesn't include derivation path)
2023-05-16 08:18:56 +00:00
func ( api * API ) GetAddressDetails ( ctx context . Context , chainID uint64 , address string ) ( * DerivedAddress , error ) {
2023-07-25 08:48:03 +00:00
result := & DerivedAddress {
Address : common . HexToAddress ( address ) ,
}
addressExists , err := api . s . accountsDB . AddressExists ( types . Address ( result . Address ) )
2022-10-21 08:01:31 +00:00
if err != nil {
2023-07-25 08:48:03 +00:00
return result , err
2022-10-21 08:01:31 +00:00
}
2022-05-18 11:31:45 +00:00
2023-07-25 08:48:03 +00:00
result . AlreadyCreated = addressExists
2023-05-16 08:18:56 +00:00
chainClient , err := api . s . rpcClient . EthClient ( chainID )
if err != nil {
2023-07-25 08:48:03 +00:00
return result , err
2023-05-16 08:18:56 +00:00
}
2022-05-18 11:31:45 +00:00
2023-07-25 08:48:03 +00:00
balance , err := api . s . tokenManager . GetChainBalance ( ctx , chainClient , result . Address )
2022-05-18 11:31:45 +00:00
if err != nil {
2023-07-25 08:48:03 +00:00
return result , err
2022-05-18 11:31:45 +00:00
}
2023-07-25 08:48:03 +00:00
result . HasActivity = balance . Cmp ( big . NewInt ( 0 ) ) != 0
return result , nil
2022-05-18 11:31:45 +00:00
}
2023-11-28 17:59:23 +00:00
func ( api * API ) SignMessage ( ctx context . Context , message types . HexBytes , address common . Address , password string ) ( string , error ) {
log . Debug ( "[WalletAPI::SignMessage]" , "message" , message , "address" , address )
return api . s . transactionManager . SignMessage ( message , address , password )
}
func ( api * API ) BuildTransaction ( ctx context . Context , chainID uint64 , sendTxArgsJSON string ) ( response * transfer . TxResponse , err error ) {
log . Debug ( "[WalletAPI::BuildTransaction]" , "chainID" , chainID , "sendTxArgsJSON" , sendTxArgsJSON )
var params transactions . SendTxArgs
err = json . Unmarshal ( [ ] byte ( sendTxArgsJSON ) , & params )
if err != nil {
return nil , err
}
return api . s . transactionManager . BuildTransaction ( chainID , params )
}
2023-12-01 16:42:08 +00:00
func ( api * API ) BuildRawTransaction ( ctx context . Context , chainID uint64 , sendTxArgsJSON string , signature string ) ( response * transfer . TxResponse , err error ) {
log . Debug ( "[WalletAPI::BuildRawTransaction]" , "chainID" , chainID , "sendTxArgsJSON" , sendTxArgsJSON , "signature" , signature )
sig , err := hex . DecodeString ( signature )
if err != nil {
return nil , err
}
var params transactions . SendTxArgs
err = json . Unmarshal ( [ ] byte ( sendTxArgsJSON ) , & params )
if err != nil {
return nil , err
}
return api . s . transactionManager . BuildRawTransaction ( chainID , params , sig )
}
2023-11-28 17:59:23 +00:00
func ( api * API ) SendTransactionWithSignature ( ctx context . Context , chainID uint64 , txType transactions . PendingTrxType ,
sendTxArgsJSON string , signature string ) ( hash types . Hash , err error ) {
log . Debug ( "[WalletAPI::SendTransactionWithSignature]" , "chainID" , chainID , "txType" , txType , "sendTxArgsJSON" , sendTxArgsJSON , "signature" , signature )
sig , err := hex . DecodeString ( signature )
if err != nil {
return hash , err
}
var params transactions . SendTxArgs
err = json . Unmarshal ( [ ] byte ( sendTxArgsJSON ) , & params )
if err != nil {
return hash , err
}
return api . s . transactionManager . SendTransactionWithSignature ( chainID , txType , params , sig )
}
2023-06-12 10:49:32 +00:00
func ( api * API ) CreateMultiTransaction ( ctx context . Context , multiTransactionCommand * transfer . MultiTransactionCommand , data [ ] * bridge . TransactionBridge , password string ) ( * transfer . MultiTransactionCommandResult , error ) {
2022-07-15 08:53:56 +00:00
log . Debug ( "[WalletAPI:: CreateMultiTransaction] create multi transaction" )
2023-06-12 10:49:32 +00:00
return api . s . transactionManager . CreateMultiTransactionFromCommand ( ctx , multiTransactionCommand , data , api . router . bridges , password )
2022-07-15 08:53:56 +00:00
}
2023-01-12 17:54:14 +00:00
2023-09-29 17:56:27 +00:00
func ( api * API ) ProceedWithTransactionsSignatures ( ctx context . Context , signatures map [ string ] transfer . SignatureDetails ) ( * transfer . MultiTransactionCommandResult , error ) {
log . Debug ( "[WalletAPI:: ProceedWithTransactionsSignatures] sign with signatures and send multi transaction" )
return api . s . transactionManager . ProceedWithTransactionsSignatures ( ctx , signatures )
}
2023-03-01 19:35:19 +00:00
func ( api * API ) GetMultiTransactions ( ctx context . Context , transactionIDs [ ] transfer . MultiTransactionIDType ) ( [ ] * transfer . MultiTransaction , error ) {
2023-06-13 09:25:23 +00:00
log . Debug ( "wallet.api.GetMultiTransactions" , "IDs.len" , len ( transactionIDs ) )
2023-03-01 19:35:19 +00:00
return api . s . transactionManager . GetMultiTransactions ( ctx , transactionIDs )
}
2023-02-17 14:11:07 +00:00
func ( api * API ) GetCachedCurrencyFormats ( ) ( currency . FormatPerSymbol , error ) {
log . Debug ( "call to GetCachedCurrencyFormats" )
return api . s . currency . GetCachedCurrencyFormats ( )
2023-01-12 17:54:14 +00:00
}
2023-02-17 14:11:07 +00:00
func ( api * API ) FetchAllCurrencyFormats ( ) ( currency . FormatPerSymbol , error ) {
log . Debug ( "call to FetchAllCurrencyFormats" )
return api . s . currency . FetchAllCurrencyFormats ( )
2023-01-12 17:54:14 +00:00
}
2023-04-21 11:59:29 +00:00
2023-09-12 10:19:15 +00:00
func ( api * API ) FilterActivityAsync ( requestID int32 , addresses [ ] common . Address , allAddresses bool , chainIDs [ ] wcommon . ChainID , filter activity . Filter , offset int , limit int ) error {
log . Debug ( "wallet.api.FilterActivityAsync" , "requestID" , requestID , "addr.count" , len ( addresses ) , "allAddresses" , allAddresses , "chainIDs.count" , len ( chainIDs ) , "offset" , offset , "limit" , limit )
2023-06-13 09:25:23 +00:00
2023-09-12 10:19:15 +00:00
api . s . activity . FilterActivityAsync ( requestID , addresses , allAddresses , chainIDs , filter , offset , limit )
2023-06-22 11:28:35 +00:00
return nil
2023-04-21 11:59:29 +00:00
}
2023-06-15 17:00:40 +00:00
2023-09-19 20:58:13 +00:00
func ( api * API ) CancelActivityFilterTask ( requestID int32 ) error {
log . Debug ( "wallet.api.CancelActivityFilterTask" , "requestID" , requestID )
api . s . activity . CancelFilterTask ( requestID )
return nil
}
2023-08-24 12:23:40 +00:00
func ( api * API ) GetMultiTxDetails ( ctx context . Context , multiTxID int ) ( * activity . EntryDetails , error ) {
log . Debug ( "wallet.api.GetMultiTxDetails" , "multiTxID" , multiTxID )
return api . s . activity . GetMultiTxDetails ( ctx , multiTxID )
}
func ( api * API ) GetTxDetails ( ctx context . Context , id string ) ( * activity . EntryDetails , error ) {
log . Debug ( "wallet.api.GetTxDetails" , "id" , id )
return api . s . activity . GetTxDetails ( ctx , id )
}
2023-10-02 11:46:05 +00:00
func ( api * API ) GetRecipientsAsync ( requestID int32 , chainIDs [ ] wcommon . ChainID , addresses [ ] common . Address , offset int , limit int ) ( ignored bool , err error ) {
log . Debug ( "wallet.api.GetRecipientsAsync" , "addresses.len" , len ( addresses ) , "chainIDs.len" , len ( chainIDs ) , "offset" , offset , "limit" , limit )
2023-06-15 17:00:40 +00:00
2023-10-02 11:46:05 +00:00
ignored = api . s . activity . GetRecipientsAsync ( requestID , chainIDs , addresses , offset , limit )
2023-06-22 11:28:35 +00:00
return ignored , err
2023-06-15 17:00:40 +00:00
}
2023-06-21 08:01:31 +00:00
2023-07-24 22:54:53 +00:00
func ( api * API ) GetOldestActivityTimestampAsync ( requestID int32 , addresses [ ] common . Address ) error {
2023-06-21 08:01:31 +00:00
log . Debug ( "wallet.api.GetOldestActivityTimestamp" , "addresses.len" , len ( addresses ) )
2023-06-22 11:28:35 +00:00
2023-07-24 22:54:53 +00:00
api . s . activity . GetOldestTimestampAsync ( requestID , addresses )
2023-06-22 11:28:35 +00:00
return nil
2023-06-21 08:01:31 +00:00
}
2023-07-12 05:58:01 +00:00
2023-10-03 10:49:04 +00:00
func ( api * API ) GetActivityCollectiblesAsync ( requestID int32 , chainIDs [ ] wcommon . ChainID , addresses [ ] common . Address , offset int , limit int ) error {
log . Debug ( "wallet.api.GetActivityCollectiblesAsync" , "addresses.len" , len ( addresses ) , "chainIDs.len" , len ( chainIDs ) , "offset" , offset , "limit" , limit )
api . s . activity . GetActivityCollectiblesAsync ( requestID , chainIDs , addresses , offset , limit )
return nil
}
2023-07-12 05:58:01 +00:00
func ( api * API ) FetchChainIDForURL ( ctx context . Context , rpcURL string ) ( * big . Int , error ) {
2023-10-30 16:58:57 +00:00
log . Debug ( "wallet.api.VerifyURL" , "rpcURL" , rpcURL )
2023-07-12 05:58:01 +00:00
rpcClient , err := gethrpc . Dial ( rpcURL )
if err != nil {
return nil , fmt . Errorf ( "dial upstream server: %s" , err )
}
client := ethclient . NewClient ( rpcClient )
return client . ChainID ( ctx )
}
2023-10-30 16:58:57 +00:00
2023-11-06 19:04:42 +00:00
// WCPairSessionProposal responds to "session_proposal" event
2023-10-30 16:58:57 +00:00
func ( api * API ) WCPairSessionProposal ( ctx context . Context , sessionProposalJSON string ) ( * wc . PairSessionResponse , error ) {
log . Debug ( "wallet.api.wc.PairSessionProposal" , "proposal.len" , len ( sessionProposalJSON ) )
var data wc . SessionProposal
err := json . Unmarshal ( [ ] byte ( sessionProposalJSON ) , & data )
if err != nil {
return nil , err
}
return api . s . walletConnect . PairSessionProposal ( data )
}
2023-11-06 19:04:42 +00:00
2023-12-13 14:05:55 +00:00
// WCSaveOrUpdateSession records a session established between Status app and dapp
func ( api * API ) WCSaveOrUpdateSession ( ctx context . Context , sessionProposalJSON string ) error {
log . Debug ( "wallet.api.wc.WCSaveOrUpdateSession" , "proposal.len" , len ( sessionProposalJSON ) )
2023-11-19 17:29:17 +00:00
2023-12-13 14:05:55 +00:00
var data wc . Session
2023-11-19 17:29:17 +00:00
err := json . Unmarshal ( [ ] byte ( sessionProposalJSON ) , & data )
if err != nil {
return err
}
2023-12-13 14:05:55 +00:00
return api . s . walletConnect . SaveOrUpdateSession ( data )
2023-11-26 15:50:12 +00:00
}
2023-12-13 14:05:55 +00:00
// WCChangeSessionState changes the active state of a session
func ( api * API ) WCChangeSessionState ( ctx context . Context , topic walletconnect . Topic , active bool ) error {
log . Debug ( "wallet.api.wc.WCChangeSessionState" , "topic" , topic , "active" , active )
2023-11-19 17:29:17 +00:00
2023-12-13 14:05:55 +00:00
return api . s . walletConnect . ChangeSessionState ( topic , active )
2023-11-19 17:29:17 +00:00
}
2023-11-06 19:04:42 +00:00
// WCSessionRequest responds to "session_request" event
2023-12-01 16:42:08 +00:00
func ( api * API ) WCSessionRequest ( ctx context . Context , sessionRequestJSON string ) ( * transfer . TxResponse , error ) {
2023-11-17 15:28:37 +00:00
log . Debug ( "wallet.api.wc.SessionRequest" , "request.len" , len ( sessionRequestJSON ) )
2023-11-06 19:04:42 +00:00
var request wc . SessionRequest
2023-11-24 15:39:36 +00:00
err := json . Unmarshal ( [ ] byte ( sessionRequestJSON ) , & request )
2023-11-06 19:04:42 +00:00
if err != nil {
return nil , err
}
2023-11-17 15:28:37 +00:00
return api . s . walletConnect . SessionRequest ( request )
2023-11-06 19:04:42 +00:00
}
2023-12-06 13:53:23 +00:00
// WCAuthRequest responds to "auth_request" event
func ( api * API ) WCAuthRequest ( ctx context . Context , address common . Address , authMessage string ) ( * transfer . TxResponse , error ) {
log . Debug ( "wallet.api.wc.AuthRequest" , "address" , address , "authMessage" , authMessage )
return api . s . walletConnect . AuthRequest ( address , authMessage )
}