@cityofzion/bs-neo-legacy 0.7.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.rush/temp/operation/build/all.log +1 -0
- package/.rush/temp/operation/build/state.json +3 -0
- package/.rush/temp/package-deps_build.json +8 -6
- package/.rush/temp/shrinkwrap-deps.json +350 -101
- package/CHANGELOG.json +22 -0
- package/CHANGELOG.md +11 -0
- package/bs-neo-legacy.build.log +1 -2
- package/dist/BSNeoLegacy.d.ts +25 -24
- package/dist/BSNeoLegacy.js +176 -173
- package/dist/CryptoCompareEDSNeoLegacy.d.ts +7 -7
- package/dist/CryptoCompareEDSNeoLegacy.js +51 -41
- package/dist/DoraBDSNeoLegacy.d.ts +16 -16
- package/dist/DoraBDSNeoLegacy.js +163 -163
- package/dist/DoraESNeoLegacy.d.ts +7 -7
- package/dist/DoraESNeoLegacy.js +17 -17
- package/dist/assets/tokens/common.json +18 -18
- package/dist/assets/tokens/mainnet.json +620 -620
- package/dist/constants.d.ts +13 -13
- package/dist/constants.js +23 -23
- package/dist/index.d.ts +4 -4
- package/dist/index.js +20 -20
- package/jest.config.ts +13 -13
- package/jest.setup.ts +1 -1
- package/package.json +26 -25
- package/src/BSNeoLegacy.ts +202 -198
- package/src/CryptoCompareEDSNeoLegacy.ts +50 -40
- package/src/DoraBDSNeoLegacy.ts +173 -173
- package/src/DoraESNeoLegacy.ts +18 -18
- package/src/__tests__/BDSNeoLegacy.spec.ts +120 -120
- package/src/__tests__/BSNeoLegacy.spec.ts +135 -127
- package/src/__tests__/CryptoCompareExchange.spec.ts +48 -46
- package/src/__tests__/DoraESNeoLegacy.spec.ts +15 -15
- package/src/assets/tokens/common.json +17 -17
- package/src/assets/tokens/mainnet.json +619 -619
- package/src/constants.ts +23 -23
- package/src/index.ts +4 -4
- package/tsconfig.build.json +4 -4
- package/tsconfig.json +14 -14
- package/dist/BDSNeoLegacy.d.ts +0 -15
- package/dist/BDSNeoLegacy.js +0 -199
- package/dist/asset/tokens.json +0 -480
- package/dist/explorer/dora/DoraResponsesNeoLegacy.d.ts +0 -95
- package/dist/explorer/dora/DoraResponsesNeoLegacy.js +0 -2
- package/dist/explorer/dora/DoraRoutesNeoLegacy.d.ts +0 -7
- package/dist/explorer/dora/DoraRoutesNeoLegacy.js +0 -10
- package/dist/explorer/index.d.ts +0 -6
- package/dist/explorer/index.js +0 -23
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -22
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1280
- package/docs/classes/BDSNeoLegacy.html +0 -243
- package/docs/classes/BSNeoLegacy.html +0 -423
- package/docs/index.html +0 -70
- package/docs/interfaces/DoraNeoLegacyAsset.html +0 -103
- package/docs/interfaces/DoraNeoLegacyAssetResponse.html +0 -117
- package/docs/interfaces/DoraNeoLegacyBalance.html +0 -89
- package/docs/interfaces/DoraNeoLegacyConsensusNode.html +0 -75
- package/docs/interfaces/DoraNeoLegacyDetails.html +0 -138
- package/docs/interfaces/DoraNeoLegacyEntriesEntity.html +0 -110
- package/docs/interfaces/DoraNeoLegacyNameEntity.html +0 -75
- package/docs/interfaces/DoraNeoLegacyScriptsEntity.html +0 -75
- package/docs/interfaces/DoraNeoLegacyTransaction.html +0 -152
- package/docs/interfaces/DoraNeoLegacyTransactionsHistory.html +0 -96
- package/docs/interfaces/DoraNeoLegacyUnclaimed.html +0 -82
- package/docs/interfaces/DoraNeoLegacyVinEntity.html +0 -75
- package/docs/interfaces/DoraNeoLegacyVoutEntity.html +0 -89
- package/docs/modules.html +0 -98
- package/docs/variables/DORA_NEO_LEGACY_ASSET.html +0 -69
- package/docs/variables/DORA_NEO_LEGACY_BALANCE.html +0 -69
- package/docs/variables/DORA_NEO_LEGACY_CONTRACT.html +0 -69
- package/docs/variables/DORA_NEO_LEGACY_HISTORY_TRANSACTIONS.html +0 -69
- package/docs/variables/DORA_NEO_LEGACY_NODES.html +0 -69
- package/docs/variables/DORA_NEO_LEGACY_TRANSACTION.html +0 -69
- package/docs/variables/DORA_NEO_LEGACY_UNCLAIMED.html +0 -69
- package/docs/variables/explorerNeoLegacyOption.html +0 -74
|
@@ -1,40 +1,50 @@
|
|
|
1
|
-
import { Currency, ExchangeDataService, NetworkType, TokenPricesResponse } from '@cityofzion/blockchain-service'
|
|
2
|
-
import axios, { AxiosInstance } from 'axios'
|
|
3
|
-
import { TOKENS } from './constants'
|
|
4
|
-
|
|
5
|
-
type CryptoCompareDataResponse = {
|
|
6
|
-
RAW: {
|
|
7
|
-
[symbol: string]: {
|
|
8
|
-
[currency: string]: {
|
|
9
|
-
PRICE: number
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class CryptoCompareEDSNeoLegacy implements ExchangeDataService {
|
|
16
|
-
networkType: NetworkType
|
|
17
|
-
private axiosInstance: AxiosInstance
|
|
18
|
-
|
|
19
|
-
constructor(network: NetworkType) {
|
|
20
|
-
this.networkType = network
|
|
21
|
-
this.axiosInstance = axios.create({ baseURL: 'https://min-api.cryptocompare.com' })
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]> {
|
|
25
|
-
if (this.networkType !== 'mainnet') throw new Error('Exchange is only available on mainnet')
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
import { Currency, ExchangeDataService, NetworkType, TokenPricesResponse } from '@cityofzion/blockchain-service'
|
|
2
|
+
import axios, { AxiosInstance } from 'axios'
|
|
3
|
+
import { TOKENS } from './constants'
|
|
4
|
+
|
|
5
|
+
type CryptoCompareDataResponse = {
|
|
6
|
+
RAW: {
|
|
7
|
+
[symbol: string]: {
|
|
8
|
+
[currency: string]: {
|
|
9
|
+
PRICE: number
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class CryptoCompareEDSNeoLegacy implements ExchangeDataService {
|
|
16
|
+
networkType: NetworkType
|
|
17
|
+
private axiosInstance: AxiosInstance
|
|
18
|
+
|
|
19
|
+
constructor(network: NetworkType) {
|
|
20
|
+
this.networkType = network
|
|
21
|
+
this.axiosInstance = axios.create({ baseURL: 'https://min-api.cryptocompare.com' })
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]> {
|
|
25
|
+
if (this.networkType !== 'mainnet') throw new Error('Exchange is only available on mainnet')
|
|
26
|
+
|
|
27
|
+
const tokens = TOKENS[this.networkType]
|
|
28
|
+
const tokenSymbols = tokens.map(token => token.symbol)
|
|
29
|
+
const { data: prices } = await this.axiosInstance.get<CryptoCompareDataResponse>('/data/pricemultifull', {
|
|
30
|
+
params: {
|
|
31
|
+
fsyms: tokenSymbols.join(','),
|
|
32
|
+
tsyms: currency,
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
return Object.entries(prices.RAW)
|
|
37
|
+
.map(([symbol, priceObject]) => {
|
|
38
|
+
const price = priceObject[currency].PRICE
|
|
39
|
+
const token = tokens.find(token => token.symbol === symbol)
|
|
40
|
+
if (!token || !price) return
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
symbol,
|
|
44
|
+
price,
|
|
45
|
+
hash: token?.hash,
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
.filter((price): price is TokenPricesResponse => price !== undefined)
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/DoraBDSNeoLegacy.ts
CHANGED
|
@@ -1,173 +1,173 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BalanceResponse,
|
|
3
|
-
BlockchainDataService,
|
|
4
|
-
ContractResponse,
|
|
5
|
-
TransactionsByAddressParams,
|
|
6
|
-
TransactionsByAddressResponse,
|
|
7
|
-
TransactionResponse,
|
|
8
|
-
BDSClaimable,
|
|
9
|
-
TransactionTransferAsset,
|
|
10
|
-
Token,
|
|
11
|
-
NetworkType,
|
|
12
|
-
Network,
|
|
13
|
-
} from '@cityofzion/blockchain-service'
|
|
14
|
-
import { api } from '@cityofzion/dora-ts'
|
|
15
|
-
import { TOKENS } from './constants'
|
|
16
|
-
import { rpc } from '@cityofzion/neon-js'
|
|
17
|
-
|
|
18
|
-
export class DoraBDSNeoLegacy implements BlockchainDataService, BDSClaimable {
|
|
19
|
-
readonly network: Network
|
|
20
|
-
private readonly claimToken: Token
|
|
21
|
-
private readonly feeToken: Token
|
|
22
|
-
private readonly tokenCache: Map<string, Token> = new Map()
|
|
23
|
-
|
|
24
|
-
maxTimeToConfirmTransactionInMs: number = 1000 * 60 * 2
|
|
25
|
-
|
|
26
|
-
constructor(network: Network, feeToken: Token, claimToken: Token) {
|
|
27
|
-
if (network.type === 'custom') throw new Error('Custom network is not supported for NEO Legacy')
|
|
28
|
-
this.network = network
|
|
29
|
-
this.claimToken = claimToken
|
|
30
|
-
this.feeToken = feeToken
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async getTransaction(hash: string): Promise<TransactionResponse> {
|
|
34
|
-
const data = await api.NeoLegacyREST.transaction(hash, this.network.type)
|
|
35
|
-
if (!data || 'error' in data) throw new Error(`Transaction ${hash} not found`)
|
|
36
|
-
|
|
37
|
-
const vout: any[] = data.vout ?? []
|
|
38
|
-
|
|
39
|
-
const promises = vout.map<Promise<TransactionTransferAsset>>(async (transfer, _index, array) => {
|
|
40
|
-
const token = await this.getTokenInfo(transfer.asset)
|
|
41
|
-
return {
|
|
42
|
-
amount: String(transfer.value),
|
|
43
|
-
from: array[array.length - 1]?.address,
|
|
44
|
-
contractHash: transfer.asset,
|
|
45
|
-
to: transfer.address,
|
|
46
|
-
type: 'token',
|
|
47
|
-
token,
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
const transfers = await Promise.all(promises)
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
hash: data.txid,
|
|
54
|
-
block: data.block,
|
|
55
|
-
fee: (Number(data.sys_fee ?? 0) + Number(data.net_fee ?? 0)).toFixed(this.feeToken.decimals),
|
|
56
|
-
time: Number(data.time),
|
|
57
|
-
notifications: [], //neoLegacy doesn't have notifications
|
|
58
|
-
transfers,
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async getTransactionsByAddress({
|
|
63
|
-
address,
|
|
64
|
-
page = 1,
|
|
65
|
-
}: TransactionsByAddressParams): Promise<TransactionsByAddressResponse> {
|
|
66
|
-
const data = await api.NeoLegacyREST.getAddressAbstracts(address, page, this.network.type)
|
|
67
|
-
const transactions = new Map<string, TransactionResponse>()
|
|
68
|
-
|
|
69
|
-
const promises = data.entries.map(async entry => {
|
|
70
|
-
if (entry.address_from !== address && entry.address_to !== address) return
|
|
71
|
-
|
|
72
|
-
const token = await this.getTokenInfo(entry.asset)
|
|
73
|
-
const transfer: TransactionTransferAsset = {
|
|
74
|
-
amount: String(entry.amount),
|
|
75
|
-
from: entry.address_from ?? 'Mint',
|
|
76
|
-
to: entry.address_to ?? 'Burn',
|
|
77
|
-
type: 'token',
|
|
78
|
-
contractHash: entry.asset,
|
|
79
|
-
token,
|
|
80
|
-
}
|
|
81
|
-
const existingTransaction = transactions.get(entry.txid)
|
|
82
|
-
if (existingTransaction) {
|
|
83
|
-
existingTransaction.transfers.push(transfer)
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
transactions.set(entry.txid, {
|
|
88
|
-
block: entry.block_height,
|
|
89
|
-
hash: entry.txid,
|
|
90
|
-
time: entry.time,
|
|
91
|
-
transfers: [transfer],
|
|
92
|
-
notifications: [],
|
|
93
|
-
})
|
|
94
|
-
})
|
|
95
|
-
await Promise.all(promises)
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
totalCount: data.total_entries,
|
|
99
|
-
limit: data.page_size,
|
|
100
|
-
transactions: Array.from(transactions.values()),
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async getContract(contractHash: string): Promise<ContractResponse> {
|
|
105
|
-
const response = await api.NeoLegacyREST.contract(contractHash, this.network.type)
|
|
106
|
-
if (!response || 'error' in response) throw new Error(`Contract ${contractHash} not found`)
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
hash: response.hash,
|
|
110
|
-
name: response.name,
|
|
111
|
-
methods: [],
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async getTokenInfo(tokenHash: string): Promise<Token> {
|
|
116
|
-
const localToken = TOKENS[this.network.type].find(token => token.hash === tokenHash)
|
|
117
|
-
if (localToken) return localToken
|
|
118
|
-
|
|
119
|
-
if (this.tokenCache.has(tokenHash)) {
|
|
120
|
-
return this.tokenCache.get(tokenHash)!
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const data = await api.NeoLegacyREST.asset(tokenHash, this.network.type)
|
|
124
|
-
if (!data || 'error' in data) throw new Error(`Token ${tokenHash} not found`)
|
|
125
|
-
|
|
126
|
-
const token = {
|
|
127
|
-
decimals: data.decimals,
|
|
128
|
-
symbol: data.symbol,
|
|
129
|
-
hash: data.scripthash,
|
|
130
|
-
name: data.name,
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
this.tokenCache.set(tokenHash, token)
|
|
134
|
-
|
|
135
|
-
return token
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async getBalance(address: string): Promise<BalanceResponse[]> {
|
|
139
|
-
const data = await api.NeoLegacyREST.balance(address, this.network.type)
|
|
140
|
-
|
|
141
|
-
const promises = data.map<Promise<BalanceResponse>>(async balance => {
|
|
142
|
-
let token: Token = {
|
|
143
|
-
hash: balance.asset,
|
|
144
|
-
name: balance.asset_name,
|
|
145
|
-
symbol: balance.symbol,
|
|
146
|
-
decimals: 8,
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
token = await this.getTokenInfo(balance.asset)
|
|
151
|
-
} catch {}
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
amount: Number(balance.balance).toFixed(token.decimals),
|
|
155
|
-
token,
|
|
156
|
-
}
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
const result = await Promise.all(promises)
|
|
160
|
-
|
|
161
|
-
return result
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
async getUnclaimed(address: string): Promise<string> {
|
|
165
|
-
const { unclaimed } = await api.NeoLegacyREST.getUnclaimed(address, this.network.type)
|
|
166
|
-
return (unclaimed / 10 ** this.claimToken.decimals).toFixed(this.claimToken.decimals)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async getBlockHeight(): Promise<number> {
|
|
170
|
-
const rpcClient = new rpc.RPCClient(this.network.url)
|
|
171
|
-
return await rpcClient.getBlockCount()
|
|
172
|
-
}
|
|
173
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
BalanceResponse,
|
|
3
|
+
BlockchainDataService,
|
|
4
|
+
ContractResponse,
|
|
5
|
+
TransactionsByAddressParams,
|
|
6
|
+
TransactionsByAddressResponse,
|
|
7
|
+
TransactionResponse,
|
|
8
|
+
BDSClaimable,
|
|
9
|
+
TransactionTransferAsset,
|
|
10
|
+
Token,
|
|
11
|
+
NetworkType,
|
|
12
|
+
Network,
|
|
13
|
+
} from '@cityofzion/blockchain-service'
|
|
14
|
+
import { api } from '@cityofzion/dora-ts'
|
|
15
|
+
import { TOKENS } from './constants'
|
|
16
|
+
import { rpc } from '@cityofzion/neon-js'
|
|
17
|
+
|
|
18
|
+
export class DoraBDSNeoLegacy implements BlockchainDataService, BDSClaimable {
|
|
19
|
+
readonly network: Network
|
|
20
|
+
private readonly claimToken: Token
|
|
21
|
+
private readonly feeToken: Token
|
|
22
|
+
private readonly tokenCache: Map<string, Token> = new Map()
|
|
23
|
+
|
|
24
|
+
maxTimeToConfirmTransactionInMs: number = 1000 * 60 * 2
|
|
25
|
+
|
|
26
|
+
constructor(network: Network, feeToken: Token, claimToken: Token) {
|
|
27
|
+
if (network.type === 'custom') throw new Error('Custom network is not supported for NEO Legacy')
|
|
28
|
+
this.network = network
|
|
29
|
+
this.claimToken = claimToken
|
|
30
|
+
this.feeToken = feeToken
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getTransaction(hash: string): Promise<TransactionResponse> {
|
|
34
|
+
const data = await api.NeoLegacyREST.transaction(hash, this.network.type)
|
|
35
|
+
if (!data || 'error' in data) throw new Error(`Transaction ${hash} not found`)
|
|
36
|
+
|
|
37
|
+
const vout: any[] = data.vout ?? []
|
|
38
|
+
|
|
39
|
+
const promises = vout.map<Promise<TransactionTransferAsset>>(async (transfer, _index, array) => {
|
|
40
|
+
const token = await this.getTokenInfo(transfer.asset)
|
|
41
|
+
return {
|
|
42
|
+
amount: String(transfer.value),
|
|
43
|
+
from: array[array.length - 1]?.address,
|
|
44
|
+
contractHash: transfer.asset,
|
|
45
|
+
to: transfer.address,
|
|
46
|
+
type: 'token',
|
|
47
|
+
token,
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
const transfers = await Promise.all(promises)
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
hash: data.txid,
|
|
54
|
+
block: data.block,
|
|
55
|
+
fee: (Number(data.sys_fee ?? 0) + Number(data.net_fee ?? 0)).toFixed(this.feeToken.decimals),
|
|
56
|
+
time: Number(data.time),
|
|
57
|
+
notifications: [], //neoLegacy doesn't have notifications
|
|
58
|
+
transfers,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async getTransactionsByAddress({
|
|
63
|
+
address,
|
|
64
|
+
page = 1,
|
|
65
|
+
}: TransactionsByAddressParams): Promise<TransactionsByAddressResponse> {
|
|
66
|
+
const data = await api.NeoLegacyREST.getAddressAbstracts(address, page, this.network.type)
|
|
67
|
+
const transactions = new Map<string, TransactionResponse>()
|
|
68
|
+
|
|
69
|
+
const promises = data.entries.map(async entry => {
|
|
70
|
+
if (entry.address_from !== address && entry.address_to !== address) return
|
|
71
|
+
|
|
72
|
+
const token = await this.getTokenInfo(entry.asset)
|
|
73
|
+
const transfer: TransactionTransferAsset = {
|
|
74
|
+
amount: String(entry.amount),
|
|
75
|
+
from: entry.address_from ?? 'Mint',
|
|
76
|
+
to: entry.address_to ?? 'Burn',
|
|
77
|
+
type: 'token',
|
|
78
|
+
contractHash: entry.asset,
|
|
79
|
+
token,
|
|
80
|
+
}
|
|
81
|
+
const existingTransaction = transactions.get(entry.txid)
|
|
82
|
+
if (existingTransaction) {
|
|
83
|
+
existingTransaction.transfers.push(transfer)
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
transactions.set(entry.txid, {
|
|
88
|
+
block: entry.block_height,
|
|
89
|
+
hash: entry.txid,
|
|
90
|
+
time: entry.time,
|
|
91
|
+
transfers: [transfer],
|
|
92
|
+
notifications: [],
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
await Promise.all(promises)
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
totalCount: data.total_entries,
|
|
99
|
+
limit: data.page_size,
|
|
100
|
+
transactions: Array.from(transactions.values()),
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async getContract(contractHash: string): Promise<ContractResponse> {
|
|
105
|
+
const response = await api.NeoLegacyREST.contract(contractHash, this.network.type)
|
|
106
|
+
if (!response || 'error' in response) throw new Error(`Contract ${contractHash} not found`)
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
hash: response.hash,
|
|
110
|
+
name: response.name,
|
|
111
|
+
methods: [],
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async getTokenInfo(tokenHash: string): Promise<Token> {
|
|
116
|
+
const localToken = TOKENS[this.network.type].find(token => token.hash === tokenHash)
|
|
117
|
+
if (localToken) return localToken
|
|
118
|
+
|
|
119
|
+
if (this.tokenCache.has(tokenHash)) {
|
|
120
|
+
return this.tokenCache.get(tokenHash)!
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const data = await api.NeoLegacyREST.asset(tokenHash, this.network.type)
|
|
124
|
+
if (!data || 'error' in data) throw new Error(`Token ${tokenHash} not found`)
|
|
125
|
+
|
|
126
|
+
const token = {
|
|
127
|
+
decimals: data.decimals,
|
|
128
|
+
symbol: data.symbol,
|
|
129
|
+
hash: data.scripthash,
|
|
130
|
+
name: data.name,
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
this.tokenCache.set(tokenHash, token)
|
|
134
|
+
|
|
135
|
+
return token
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async getBalance(address: string): Promise<BalanceResponse[]> {
|
|
139
|
+
const data = await api.NeoLegacyREST.balance(address, this.network.type)
|
|
140
|
+
|
|
141
|
+
const promises = data.map<Promise<BalanceResponse>>(async balance => {
|
|
142
|
+
let token: Token = {
|
|
143
|
+
hash: balance.asset,
|
|
144
|
+
name: balance.asset_name,
|
|
145
|
+
symbol: balance.symbol,
|
|
146
|
+
decimals: 8,
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
token = await this.getTokenInfo(balance.asset)
|
|
151
|
+
} catch {}
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
amount: Number(balance.balance).toFixed(token.decimals),
|
|
155
|
+
token,
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
const result = await Promise.all(promises)
|
|
160
|
+
|
|
161
|
+
return result
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async getUnclaimed(address: string): Promise<string> {
|
|
165
|
+
const { unclaimed } = await api.NeoLegacyREST.getUnclaimed(address, this.network.type)
|
|
166
|
+
return (unclaimed / 10 ** this.claimToken.decimals).toFixed(this.claimToken.decimals)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async getBlockHeight(): Promise<number> {
|
|
170
|
+
const rpcClient = new rpc.RPCClient(this.network.url)
|
|
171
|
+
return await rpcClient.getBlockCount()
|
|
172
|
+
}
|
|
173
|
+
}
|
package/src/DoraESNeoLegacy.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { BuildNftUrlParams, ExplorerService, NetworkType } from '@cityofzion/blockchain-service'
|
|
2
|
-
|
|
3
|
-
export class DoraESNeoLegacy implements ExplorerService {
|
|
4
|
-
private networkType: NetworkType
|
|
5
|
-
|
|
6
|
-
constructor(networkType: NetworkType) {
|
|
7
|
-
this.networkType = networkType
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
buildTransactionUrl(hash: string): string {
|
|
11
|
-
if (this.networkType === 'custom') throw new Error('DoraESNeoLegacy does not support custom network')
|
|
12
|
-
return `https://dora.coz.io/transaction/neo2/${this.networkType}/${hash}`
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
buildNftUrl(_params: BuildNftUrlParams): string {
|
|
16
|
-
throw new Error('DoraESNeoLegacy does not support nft')
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
import { BuildNftUrlParams, ExplorerService, NetworkType } from '@cityofzion/blockchain-service'
|
|
2
|
+
|
|
3
|
+
export class DoraESNeoLegacy implements ExplorerService {
|
|
4
|
+
private networkType: NetworkType
|
|
5
|
+
|
|
6
|
+
constructor(networkType: NetworkType) {
|
|
7
|
+
this.networkType = networkType
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
buildTransactionUrl(hash: string): string {
|
|
11
|
+
if (this.networkType === 'custom') throw new Error('DoraESNeoLegacy does not support custom network')
|
|
12
|
+
return `https://dora.coz.io/transaction/neo2/${this.networkType}/${hash}`
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
buildNftUrl(_params: BuildNftUrlParams): string {
|
|
16
|
+
throw new Error('DoraESNeoLegacy does not support nft')
|
|
17
|
+
}
|
|
18
|
+
}
|