-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
102 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
// place files you want to import through the `$lib` alias in this folder. | ||
// Delete this entire file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {APIClient, API, PublicKey} from '@wharfkit/antelope' | ||
import type {PermissionLevelType} from '@wharfkit/antelope' | ||
import type {Chain} from './chains' | ||
|
||
export const networkRequest = ( | ||
publicKey: PublicKey, | ||
chain: Chain, | ||
apiClient?: APIClient | ||
): Promise<PermissionLevelType[]> => { | ||
return new Promise((resolve, reject) => { | ||
const client = apiClient || new APIClient(chain) | ||
const timeoutId = setTimeout(() => { | ||
reject(new Error('Request timed out.')) | ||
}, 1000) | ||
|
||
client.v1.chain | ||
.get_accounts_by_authorizers({ | ||
keys: [publicKey], | ||
}) | ||
.then((response: API.v1.AccountsByAuthorizers) => { | ||
clearTimeout(timeoutId) | ||
resolve( | ||
response.accounts.map((account) => ({ | ||
actor: account.account_name, | ||
permission: account.permission_name, | ||
})) | ||
) | ||
}) | ||
.catch((error) => { | ||
clearTimeout(timeoutId) | ||
reject(error) | ||
}) | ||
}) | ||
} | ||
|
||
export const lookupNetwork = async (publicKey: PublicKey, chain: Chain, apiClient?: APIClient) => { | ||
try { | ||
const accounts = await networkRequest(publicKey, chain, apiClient) | ||
return {chain, accounts} | ||
} catch (error) { | ||
console.warn(`Lookup error on ${chain.name}: ${error}`) | ||
return {chain, accounts: []} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
tests/mock-data/0d57e0af5e51f16e321dda5a90ff35b8673e2c1d.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"request": { | ||
"path": "https://jungle4.greymass.com/v1/chain/get_accounts_by_authorizers", | ||
"params": { | ||
"method": "POST", | ||
"body": "{\"keys\":[\"PUB_K1_65BFgzcH8uZW837HqadGcREfNViBV6Fqc1LsmwcWdfUCZhX7vh\"]}", | ||
"headers": {} | ||
} | ||
}, | ||
"status": 200, | ||
"json": { | ||
"accounts": [ | ||
{ | ||
"account_name": "testerman123", | ||
"permission_name": "owner", | ||
"authorizing_key": "EOS65BFgzcH8uZW837HqadGcREfNViBV6Fqc1LsmwcWdfUCayHQzf", | ||
"weight": 1, | ||
"threshold": 1 | ||
}, | ||
{ | ||
"account_name": "testerman123", | ||
"permission_name": "active", | ||
"authorizing_key": "EOS65BFgzcH8uZW837HqadGcREfNViBV6Fqc1LsmwcWdfUCayHQzf", | ||
"weight": 1, | ||
"threshold": 1 | ||
} | ||
] | ||
}, | ||
"text": "{\"accounts\":[{\"account_name\":\"testerman123\",\"permission_name\":\"owner\",\"authorizing_key\":\"EOS65BFgzcH8uZW837HqadGcREfNViBV6Fqc1LsmwcWdfUCayHQzf\",\"weight\":1,\"threshold\":1},{\"account_name\":\"testerman123\",\"permission_name\":\"active\",\"authorizing_key\":\"EOS65BFgzcH8uZW837HqadGcREfNViBV6Fqc1LsmwcWdfUCayHQzf\",\"weight\":1,\"threshold\":1}]}" | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/mock-data/be06b2c036301d5738c7e72d682e07f0454ae35a.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"request": { | ||
"path": "https://jungle4.greymass.com/v1/chain/get_accounts_by_authorizers", | ||
"params": { | ||
"method": "POST", | ||
"body": "{\"keys\":[\"PUB_K1_8hiZaTNknE75KH2UmBNqcVFN4u3vgJ8PcytevjygaJ6aBNaT59\"]}", | ||
"headers": {} | ||
} | ||
}, | ||
"status": 200, | ||
"json": { | ||
"accounts": [] | ||
}, | ||
"text": "{\"accounts\":[]}" | ||
} |