@exodus/solana-api 2.5.30 → 2.5.31-alpha.1
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/package.json +2 -2
- package/src/api.js +6 -4
- package/src/connection.js +5 -2
- package/src/tx-log/solana-monitor.js +3 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/solana-api",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.31-alpha.1",
|
|
4
4
|
"description": "Exodus internal Solana asset API wrapper",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@exodus/assets-testing": "file:../../../__testing__"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "9ec7084bcdfe14f1c6f11df393351885773046a6"
|
|
38
38
|
}
|
package/src/api.js
CHANGED
|
@@ -52,23 +52,25 @@ export class Api {
|
|
|
52
52
|
|
|
53
53
|
request(path, contentType = 'application/json') {
|
|
54
54
|
return wretch(urljoin(this.rpcUrl, path)).headers({
|
|
55
|
-
'Content-
|
|
55
|
+
'Content-Type': contentType,
|
|
56
56
|
})
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
async watchAddress({
|
|
60
60
|
address,
|
|
61
61
|
tokensAddresses = [],
|
|
62
|
+
onMessage,
|
|
62
63
|
handleAccounts,
|
|
63
64
|
handleTransfers,
|
|
64
65
|
handleReconnect,
|
|
65
66
|
reconnectDelay,
|
|
66
67
|
}) {
|
|
67
|
-
if (
|
|
68
|
+
if (this.connections[address]) return // already subscribed
|
|
68
69
|
const conn = new Connection({
|
|
69
70
|
endpoint: this.wsUrl,
|
|
70
71
|
address,
|
|
71
72
|
tokensAddresses,
|
|
73
|
+
onMsg: (json) => onMessage(json),
|
|
72
74
|
callback: (updates) =>
|
|
73
75
|
this.handleUpdates({ updates, address, handleAccounts, handleTransfers }),
|
|
74
76
|
reconnectCallback: handleReconnect,
|
|
@@ -772,8 +774,8 @@ export class Api {
|
|
|
772
774
|
if (!stakingAddresses.length) return 0
|
|
773
775
|
|
|
774
776
|
// custom endpoint!
|
|
775
|
-
const rewards = await this.request(
|
|
776
|
-
.
|
|
777
|
+
const rewards = await this.request('rewards')
|
|
778
|
+
.post({ addresses: stakingAddresses })
|
|
777
779
|
.error(500, () => ({})) // addresses not found
|
|
778
780
|
.error(400, () => ({}))
|
|
779
781
|
.json()
|
package/src/connection.js
CHANGED
|
@@ -20,6 +20,7 @@ export class Connection {
|
|
|
20
20
|
address,
|
|
21
21
|
tokensAddresses = [],
|
|
22
22
|
callback,
|
|
23
|
+
onMsg,
|
|
23
24
|
reconnectCallback = () => {},
|
|
24
25
|
reconnectDelay = DEFAULT_RECONNECT_DELAY,
|
|
25
26
|
}) {
|
|
@@ -27,6 +28,7 @@ export class Connection {
|
|
|
27
28
|
this.tokensAddresses = tokensAddresses
|
|
28
29
|
this.endpoint = endpoint
|
|
29
30
|
this.callback = callback
|
|
31
|
+
this.onMsg = onMsg
|
|
30
32
|
this.reconnectCallback = reconnectCallback
|
|
31
33
|
this.reconnectDelay = reconnectDelay
|
|
32
34
|
|
|
@@ -136,7 +138,7 @@ export class Connection {
|
|
|
136
138
|
debug('pushing msg to queue', msg)
|
|
137
139
|
this.messageQueue.push(msg) // sub results
|
|
138
140
|
}
|
|
139
|
-
this.processMessages()
|
|
141
|
+
this.processMessages(json)
|
|
140
142
|
} else {
|
|
141
143
|
if (lodash.get(this.rpcQueue, json.id)) {
|
|
142
144
|
this.rpcQueue[json.id].reject(new Error(json.error.message))
|
|
@@ -195,7 +197,8 @@ export class Connection {
|
|
|
195
197
|
}
|
|
196
198
|
}
|
|
197
199
|
|
|
198
|
-
async processMessages() {
|
|
200
|
+
async processMessages(json) {
|
|
201
|
+
if (this.onMsg) await this.onMsg(json)
|
|
199
202
|
if (this.inProcessMessages) return null
|
|
200
203
|
this.inProcessMessages = true
|
|
201
204
|
try {
|
|
@@ -41,15 +41,10 @@ export class SolanaMonitor extends BaseMonitor {
|
|
|
41
41
|
})
|
|
42
42
|
return this.api.watchAddress({
|
|
43
43
|
address,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
handleAccounts: (updates) => this.accountsCallback({ updates, walletAccount }),
|
|
48
|
-
handleTransfers: (txs) => {
|
|
49
|
-
// new SOL tx, ticking monitor
|
|
50
|
-
this.tick({ walletAccount }) // it will cause refresh for both sender/receiver. Without necessarily fetching the tx if it's not finalized in the node.
|
|
44
|
+
onMessage: (json) => {
|
|
45
|
+
// new SOL tx event, tick monitor with 15 sec delay (to avoid hitting delayed nodes)
|
|
46
|
+
setTimeout(() => this.tick({ walletAccount }), 15_000)
|
|
51
47
|
},
|
|
52
|
-
*/
|
|
53
48
|
})
|
|
54
49
|
}
|
|
55
50
|
|