@audius/sdk 1.0.34 → 1.0.35
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/dist/index.cjs.js +3371 -185
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +3371 -185
- package/dist/index.esm.js.map +1 -1
- package/dist/legacy.js +3371 -185
- package/dist/legacy.js.map +1 -1
- package/dist/native-libs.js +3371 -185
- package/dist/native-libs.js.map +1 -1
- package/dist/services/creatorNode/CreatorNode.d.ts +1 -1
- package/package.json +2 -2
- package/src/sanityChecks/rolloverNodes.ts +26 -10
- package/src/services/creatorNode/CreatorNode.ts +1 -1
|
@@ -76,7 +76,7 @@ export declare class CreatorNode {
|
|
|
76
76
|
* @param timeout max time alloted for clock request
|
|
77
77
|
* @param params optional query string params
|
|
78
78
|
*/
|
|
79
|
-
static getClockValue(endpoint: string, wallet: string, timeout
|
|
79
|
+
static getClockValue(endpoint: string, wallet: string, timeout?: number, params?: Record<string, string>): Promise<any>;
|
|
80
80
|
/**
|
|
81
81
|
* Checks if a download is available from provided creator node endpoints
|
|
82
82
|
* @param endpoints creator node endpoints
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Nullable, Utils } from '../utils'
|
|
2
2
|
import { CreatorNode } from '../services/creatorNode'
|
|
3
3
|
import type { AudiusLibs } from '../AudiusLibs'
|
|
4
|
+
import maxBy from 'lodash/maxBy'
|
|
4
5
|
|
|
5
6
|
const THREE_SECONDS = 3000
|
|
6
7
|
const MAX_TRIES = 3
|
|
@@ -23,15 +24,26 @@ const checkPrimaryHealthy = async (
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
/** Gets new endpoints from a user's secondaries */
|
|
26
|
-
const getNewPrimary = async (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
const getNewPrimary = async (secondaries: string[], wallet: string) => {
|
|
28
|
+
const secondaryStatuses = (
|
|
29
|
+
await Promise.all(
|
|
30
|
+
secondaries.map(async (secondary) => {
|
|
31
|
+
try {
|
|
32
|
+
const clockValue = await CreatorNode.getClockValue(secondary, wallet)
|
|
33
|
+
if (clockValue) return { secondary, clockValue }
|
|
34
|
+
return undefined
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.warn(e)
|
|
37
|
+
return undefined
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
)
|
|
41
|
+
).filter(Boolean)
|
|
42
|
+
const max = maxBy(secondaryStatuses, (s) => s?.clockValue)?.secondary
|
|
43
|
+
if (!max) {
|
|
44
|
+
throw new Error(`Could not find valid secondaries for user ${secondaries}`)
|
|
33
45
|
}
|
|
34
|
-
|
|
46
|
+
return max
|
|
35
47
|
}
|
|
36
48
|
|
|
37
49
|
export const rolloverNodes = async (
|
|
@@ -54,7 +66,7 @@ export const rolloverNodes = async (
|
|
|
54
66
|
|
|
55
67
|
try {
|
|
56
68
|
// Get a new primary
|
|
57
|
-
const newPrimary = await getNewPrimary(
|
|
69
|
+
const newPrimary = await getNewPrimary(secondaries, user.wallet!)
|
|
58
70
|
const index = secondaries.indexOf(newPrimary)
|
|
59
71
|
// Get new secondaries and backfill up to 2
|
|
60
72
|
let newSecondaries = [...secondaries]
|
|
@@ -85,7 +97,11 @@ export const rolloverNodes = async (
|
|
|
85
97
|
console.debug(
|
|
86
98
|
`Sanity Check - rolloverNodes - new nodes ${newMetadata.creator_node_endpoint}`
|
|
87
99
|
)
|
|
88
|
-
await libs.User?.updateCreator(
|
|
100
|
+
await libs.User?.updateCreator(
|
|
101
|
+
user.user_id,
|
|
102
|
+
newMetadata,
|
|
103
|
+
true /* useEntityManager */
|
|
104
|
+
)
|
|
89
105
|
} catch (e) {
|
|
90
106
|
console.error(e)
|
|
91
107
|
}
|