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