@audius/sdk 0.0.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/.eslintrc +38 -0
- package/.prettierrc.js +1 -0
- package/.python-version +1 -0
- package/Dockerfile +15 -0
- package/README.md +3 -0
- package/babel.config.js +3 -0
- package/data-contracts/ABIs/AdminUpgradeabilityProxy.json +132 -0
- package/data-contracts/ABIs/BaseAdminUpgradeabilityProxy.json +113 -0
- package/data-contracts/ABIs/BaseUpgradeabilityProxy.json +22 -0
- package/data-contracts/ABIs/DiscoveryProviderFactory.json +189 -0
- package/data-contracts/ABIs/DiscoveryProviderFactoryInterface.json +61 -0
- package/data-contracts/ABIs/DiscoveryProviderStorage.json +205 -0
- package/data-contracts/ABIs/DiscoveryProviderStorageInterface.json +65 -0
- package/data-contracts/ABIs/ECDSA.json +4 -0
- package/data-contracts/ABIs/IPLDBlacklistFactory.json +168 -0
- package/data-contracts/ABIs/Initializable.json +4 -0
- package/data-contracts/ABIs/Migrations.json +67 -0
- package/data-contracts/ABIs/OpenZeppelinUpgradesAddress.json +4 -0
- package/data-contracts/ABIs/Ownable.json +79 -0
- package/data-contracts/ABIs/PlaylistFactory.json +669 -0
- package/data-contracts/ABIs/PlaylistFactoryInterface.json +42 -0
- package/data-contracts/ABIs/PlaylistStorage.json +250 -0
- package/data-contracts/ABIs/PlaylistStorageInterface.json +129 -0
- package/data-contracts/ABIs/Proxy.json +10 -0
- package/data-contracts/ABIs/Registry.json +240 -0
- package/data-contracts/ABIs/RegistryContract.json +102 -0
- package/data-contracts/ABIs/RegistryContractInterface.json +28 -0
- package/data-contracts/ABIs/RegistryInterface.json +66 -0
- package/data-contracts/ABIs/SigningLogic.json +43 -0
- package/data-contracts/ABIs/SigningLogicInitializable.json +46 -0
- package/data-contracts/ABIs/SocialFeatureFactory.json +460 -0
- package/data-contracts/ABIs/SocialFeatureStorage.json +225 -0
- package/data-contracts/ABIs/SocialFeatureStorageInterface.json +123 -0
- package/data-contracts/ABIs/TestContract.json +135 -0
- package/data-contracts/ABIs/TestContractInterface.json +19 -0
- package/data-contracts/ABIs/TestContractWithStorage.json +165 -0
- package/data-contracts/ABIs/TestContractWithStorageInterface.json +24 -0
- package/data-contracts/ABIs/TestStorage.json +144 -0
- package/data-contracts/ABIs/TestStorageInterface.json +42 -0
- package/data-contracts/ABIs/TestUserReplicaSetManager.json +432 -0
- package/data-contracts/ABIs/TrackFactory.json +391 -0
- package/data-contracts/ABIs/TrackFactoryInterface.json +73 -0
- package/data-contracts/ABIs/TrackStorage.json +223 -0
- package/data-contracts/ABIs/TrackStorageInterface.json +121 -0
- package/data-contracts/ABIs/UpgradeabilityProxy.json +37 -0
- package/data-contracts/ABIs/UserFactory.json +657 -0
- package/data-contracts/ABIs/UserFactoryInterface.json +65 -0
- package/data-contracts/ABIs/UserLibraryFactory.json +334 -0
- package/data-contracts/ABIs/UserReplicaSetManager.json +418 -0
- package/data-contracts/ABIs/UserStorage.json +233 -0
- package/data-contracts/ABIs/UserStorageInterface.json +93 -0
- package/data-contracts/signatureSchemas.ts +1236 -0
- package/dist/core.d.ts +446 -0
- package/dist/core.js +769 -0
- package/dist/core.js.map +1 -0
- package/dist/index.d.ts +689 -0
- package/dist/index.js +72850 -0
- package/dist/index.js.map +1 -0
- package/eth-contracts/ABIs/Address.json +4 -0
- package/eth-contracts/ABIs/AudiusAdminUpgradeabilityProxy.json +105 -0
- package/eth-contracts/ABIs/AudiusClaimDistributor.json +4968 -0
- package/eth-contracts/ABIs/AudiusToken.json +724 -0
- package/eth-contracts/ABIs/BaseUpgradeabilityProxy.json +23 -0
- package/eth-contracts/ABIs/Checkpointing.json +4 -0
- package/eth-contracts/ABIs/ClaimsManager.json +539 -0
- package/eth-contracts/ABIs/Context.json +11 -0
- package/eth-contracts/ABIs/DelegateManager.json +989 -0
- package/eth-contracts/ABIs/DelegateManagerV2.json +1049 -0
- package/eth-contracts/ABIs/DelegateManagerV2Bad.json +1049 -0
- package/eth-contracts/ABIs/ERC20.json +252 -0
- package/eth-contracts/ABIs/ERC20Burnable.json +287 -0
- package/eth-contracts/ABIs/ERC20Detailed.json +270 -0
- package/eth-contracts/ABIs/ERC20Mintable.json +364 -0
- package/eth-contracts/ABIs/ERC20Pausable.json +397 -0
- package/eth-contracts/ABIs/EthRewardsManager.json +174 -0
- package/eth-contracts/ABIs/Governance.json +938 -0
- package/eth-contracts/ABIs/GovernanceUpgraded.json +953 -0
- package/eth-contracts/ABIs/GovernanceV2.json +938 -0
- package/eth-contracts/ABIs/IERC20.json +200 -0
- package/eth-contracts/ABIs/Initializable.json +4 -0
- package/eth-contracts/ABIs/InitializableV2.json +14 -0
- package/eth-contracts/ABIs/Migrations.json +71 -0
- package/eth-contracts/ABIs/MinterRole.json +91 -0
- package/eth-contracts/ABIs/MockAccount.json +62 -0
- package/eth-contracts/ABIs/MockDelegateManager.json +55 -0
- package/eth-contracts/ABIs/MockStakingCaller.json +259 -0
- package/eth-contracts/ABIs/MockWormhole.json +106 -0
- package/eth-contracts/ABIs/OpenZeppelinUpgradesAddress.json +4 -0
- package/eth-contracts/ABIs/Ownable.json +93 -0
- package/eth-contracts/ABIs/Pausable.json +150 -0
- package/eth-contracts/ABIs/PauserRole.json +91 -0
- package/eth-contracts/ABIs/Proxy.json +10 -0
- package/eth-contracts/ABIs/Registry.json +288 -0
- package/eth-contracts/ABIs/Roles.json +4 -0
- package/eth-contracts/ABIs/SafeERC20.json +4 -0
- package/eth-contracts/ABIs/SafeMath.json +4 -0
- package/eth-contracts/ABIs/ServiceProviderFactory.json +1153 -0
- package/eth-contracts/ABIs/ServiceTypeManager.json +337 -0
- package/eth-contracts/ABIs/Staking.json +555 -0
- package/eth-contracts/ABIs/StakingUpgraded.json +570 -0
- package/eth-contracts/ABIs/TestContract.json +44 -0
- package/eth-contracts/ABIs/TrustedNotifierManager.json +265 -0
- package/eth-contracts/ABIs/Uint256Helpers.json +4 -0
- package/eth-contracts/ABIs/UpgradeabilityProxy.json +40 -0
- package/eth-contracts/ABIs/Wormhole.json +45 -0
- package/eth-contracts/ABIs/WormholeClient.json +155 -0
- package/examples/file.mp3 +0 -0
- package/examples/initAudiusLibs.js +86 -0
- package/examples/initializeVersions.js +95 -0
- package/examples/pic.jpg +0 -0
- package/initScripts/configureLocalDiscProv.js +167 -0
- package/initScripts/helpers/claim.js +43 -0
- package/initScripts/helpers/distributeTokens.js +24 -0
- package/initScripts/helpers/spRegistration.js +138 -0
- package/initScripts/helpers/utils.js +34 -0
- package/initScripts/helpers/version.js +93 -0
- package/initScripts/local.js +617 -0
- package/initScripts/mainnet.js +131 -0
- package/initScripts/manageProdRelayerWallets.js +191 -0
- package/package.json +125 -0
- package/rollup.config.js +164 -0
- package/scripts/AudiusClaimDistributor.json +4968 -0
- package/scripts/Wormhole.json +155 -0
- package/scripts/addCIDToIpldBlacklist.js +124 -0
- package/scripts/circleci-test.sh +53 -0
- package/scripts/communityRewards/transferCommunityRewardsToSolana.js +222 -0
- package/scripts/ipfs.sh +58 -0
- package/scripts/migrate_contracts.sh +25 -0
- package/scripts/reset.sh +65 -0
- package/scripts/test.sh +77 -0
- package/src/api/account.js +670 -0
- package/src/api/base.js +122 -0
- package/src/api/file.js +168 -0
- package/src/api/playlist.js +328 -0
- package/src/api/rewards.d.ts +4 -0
- package/src/api/rewards.js +682 -0
- package/src/api/serviceProvider.js +154 -0
- package/src/api/track.js +604 -0
- package/src/api/user.js +888 -0
- package/src/api/user.test.js +172 -0
- package/src/constants.ts +7 -0
- package/src/core.ts +3 -0
- package/src/index.js +6 -0
- package/src/libs.d.ts +3 -0
- package/src/libs.js +619 -0
- package/src/sanityChecks/addSecondaries.js +40 -0
- package/src/sanityChecks/assignReplicaSetIfNecessary.js +10 -0
- package/src/sanityChecks/index.d.ts +9 -0
- package/src/sanityChecks/index.js +31 -0
- package/src/sanityChecks/isCreator.js +73 -0
- package/src/sanityChecks/needsRecoveryEmail.js +20 -0
- package/src/sanityChecks/rolloverNodes.js +74 -0
- package/src/sanityChecks/sanitizeNodes.js +24 -0
- package/src/sanityChecks/syncNodes.js +28 -0
- package/src/sdk/constants.ts +10 -0
- package/src/sdk/index.ts +1 -0
- package/src/sdk/oauth/Oauth.ts +265 -0
- package/src/sdk/oauth/index.ts +1 -0
- package/src/sdk/sdk.ts +102 -0
- package/src/service-selection/ServiceSelection.test.ts +320 -0
- package/src/service-selection/ServiceSelection.ts +460 -0
- package/src/service-selection/constants.ts +14 -0
- package/src/service-selection/index.ts +1 -0
- package/src/services/ABIDecoder/AudiusABIDecoder.ts +71 -0
- package/src/services/ABIDecoder/index.ts +1 -0
- package/src/services/comstock/Comstock.ts +39 -0
- package/src/services/comstock/index.ts +1 -0
- package/src/services/contracts/ContractClient.ts +227 -0
- package/src/services/contracts/GovernedContractClient.ts +53 -0
- package/src/services/contracts/ProviderSelection.ts +42 -0
- package/src/services/creatorNode/CreatorNode.ts +1065 -0
- package/src/services/creatorNode/CreatorNodeSelection.test.ts +997 -0
- package/src/services/creatorNode/CreatorNodeSelection.ts +488 -0
- package/src/services/creatorNode/constants.ts +10 -0
- package/src/services/creatorNode/index.ts +2 -0
- package/src/services/dataContracts/AudiusContracts.ts +234 -0
- package/src/services/dataContracts/IPLDBlacklistFactoryClient.ts +73 -0
- package/src/services/dataContracts/PlaylistFactoryClient.ts +370 -0
- package/src/services/dataContracts/RegistryClient.ts +95 -0
- package/src/services/dataContracts/SocialFeatureFactoryClient.ts +196 -0
- package/src/services/dataContracts/TrackFactoryClient.ts +131 -0
- package/src/services/dataContracts/UserFactoryClient.ts +351 -0
- package/src/services/dataContracts/UserLibraryFactoryClient.ts +115 -0
- package/src/services/dataContracts/UserReplicaSetManagerClient.ts +206 -0
- package/src/services/dataContracts/index.ts +1 -0
- package/src/services/discoveryProvider/DiscoveryProvider.ts +1168 -0
- package/src/services/discoveryProvider/DiscoveryProviderSelection.test.ts +536 -0
- package/src/services/discoveryProvider/DiscoveryProviderSelection.ts +383 -0
- package/src/services/discoveryProvider/constants.ts +13 -0
- package/src/services/discoveryProvider/index.ts +1 -0
- package/src/services/discoveryProvider/requests.ts +629 -0
- package/src/services/ethContracts/AudiusTokenClient.ts +163 -0
- package/src/services/ethContracts/ClaimDistributionClient.ts +45 -0
- package/src/services/ethContracts/ClaimsManagerClient.ts +102 -0
- package/src/services/ethContracts/DelegateManagerClient.ts +480 -0
- package/src/services/ethContracts/EthContracts.ts +359 -0
- package/src/services/ethContracts/EthRewardsManagerClient.ts +33 -0
- package/src/services/ethContracts/GovernanceClient.ts +451 -0
- package/src/services/ethContracts/RegistryClient.ts +33 -0
- package/src/services/ethContracts/ServiceProviderFactoryClient.ts +691 -0
- package/src/services/ethContracts/ServiceTypeManagerClient.ts +112 -0
- package/src/services/ethContracts/StakingProxyClient.ts +97 -0
- package/src/services/ethContracts/TrustedNotifierManagerClient.ts +101 -0
- package/src/services/ethContracts/WormholeClient.ts +97 -0
- package/src/services/ethContracts/index.ts +1 -0
- package/src/services/ethWeb3Manager/EthWeb3Manager.ts +239 -0
- package/src/services/ethWeb3Manager/index.ts +1 -0
- package/src/services/hedgehog/Hedgehog.ts +96 -0
- package/src/services/hedgehog/index.ts +1 -0
- package/src/services/identity/IdentityService.ts +551 -0
- package/src/services/identity/index.ts +1 -0
- package/src/services/identity/requests.ts +65 -0
- package/src/services/schemaValidator/SchemaValidator.ts +105 -0
- package/src/services/schemaValidator/index.ts +1 -0
- package/src/services/schemaValidator/schemas/trackSchema.json +267 -0
- package/src/services/schemaValidator/schemas/userSchema.json +230 -0
- package/src/services/solanaAudiusData/errors.ts +20 -0
- package/src/services/solanaAudiusData/index.ts +1189 -0
- package/src/services/solanaWeb3Manager/errors.js +101 -0
- package/src/services/solanaWeb3Manager/index.d.ts +46 -0
- package/src/services/solanaWeb3Manager/index.js +655 -0
- package/src/services/solanaWeb3Manager/padBNToUint8Array.ts +7 -0
- package/src/services/solanaWeb3Manager/rewards.js +941 -0
- package/src/services/solanaWeb3Manager/rewardsAttester.ts +1093 -0
- package/src/services/solanaWeb3Manager/tokenAccount.js +149 -0
- package/src/services/solanaWeb3Manager/transactionHandler.js +345 -0
- package/src/services/solanaWeb3Manager/transfer.js +272 -0
- package/src/services/solanaWeb3Manager/userBank.js +160 -0
- package/src/services/solanaWeb3Manager/utils.d.ts +31 -0
- package/src/services/solanaWeb3Manager/utils.js +163 -0
- package/src/services/solanaWeb3Manager/wAudio.js +28 -0
- package/src/services/solanaWeb3Manager/wAudio.test.js +30 -0
- package/src/services/web3Manager/Web3Config.ts +14 -0
- package/src/services/web3Manager/Web3Manager.ts +360 -0
- package/src/services/web3Manager/XMLHttpRequest.ts +11 -0
- package/src/services/web3Manager/index.ts +2 -0
- package/src/services/wormhole/index.js +424 -0
- package/src/types.ts +8 -0
- package/src/userStateManager.ts +53 -0
- package/src/utils/apiSigning.ts +51 -0
- package/src/utils/captcha.ts +97 -0
- package/src/utils/estimateGas.ts +64 -0
- package/src/utils/fileHasher.ts +278 -0
- package/src/utils/importContractABI.d.ts +9 -0
- package/src/utils/importContractABI.js +19 -0
- package/src/utils/index.ts +11 -0
- package/src/utils/multiProvider.ts +72 -0
- package/src/utils/network.test.ts +127 -0
- package/src/utils/network.ts +308 -0
- package/src/utils/promiseFight.test.ts +87 -0
- package/src/utils/promiseFight.ts +36 -0
- package/src/utils/signatures.ts +139 -0
- package/src/utils/types.ts +34 -0
- package/src/utils/utils.test.ts +36 -0
- package/src/utils/utils.ts +235 -0
- package/src/utils/uuid.ts +14 -0
- package/src/web3.d.ts +9 -0
- package/src/web3.js +8 -0
- package/tests/assets/static_image.png +0 -0
- package/tests/assets/static_text.txt +1 -0
- package/tests/audiusTokenClientTest.js +37 -0
- package/tests/creatorNodeTest.js +19 -0
- package/tests/fileHasherTest.js +125 -0
- package/tests/governanceTest.js +382 -0
- package/tests/helpers.js +105 -0
- package/tests/index.js +14 -0
- package/tests/playlistClientTest.js +157 -0
- package/tests/providerSelectionTest.js +241 -0
- package/tests/registryClientTest.js +19 -0
- package/tests/rewardsAttesterTest.js +373 -0
- package/tests/serviceTypeManagerClientTest.js +33 -0
- package/tests/socialFeatureClientTest.js +79 -0
- package/tests/stakingTest.js +302 -0
- package/tests/trackClientTest.js +86 -0
- package/tests/userClientTest.js +121 -0
- package/tsconfig.json +10 -0
- package/types/@audius-hedgehog/index.d.ts +39 -0
- package/types/abi-decoder/index.d.ts +41 -0
package/src/libs.js
ADDED
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
const packageJSON = require('../package.json')
|
|
2
|
+
|
|
3
|
+
const { EthWeb3Manager } = require('./services/ethWeb3Manager')
|
|
4
|
+
const { SolanaAudiusData } = require('./services/solanaAudiusData/index')
|
|
5
|
+
const { Web3Manager } = require('./services/web3Manager')
|
|
6
|
+
const { EthContracts } = require('./services/ethContracts')
|
|
7
|
+
const SolanaWeb3Manager = require('./services/solanaWeb3Manager/index')
|
|
8
|
+
const { AudiusContracts } = require('./services/dataContracts/index')
|
|
9
|
+
const { IdentityService } = require('./services/identity')
|
|
10
|
+
const { Comstock } = require('./services/comstock')
|
|
11
|
+
const { Hedgehog } = require('./services/hedgehog')
|
|
12
|
+
const { CreatorNode } = require('./services/creatorNode')
|
|
13
|
+
const { DiscoveryProvider } = require('./services/discoveryProvider')
|
|
14
|
+
const Wormhole = require('./services/wormhole')
|
|
15
|
+
const { AudiusABIDecoder } = require('./services/ABIDecoder')
|
|
16
|
+
const { SchemaValidator } = require('./services/schemaValidator')
|
|
17
|
+
const { UserStateManager } = require('./userStateManager')
|
|
18
|
+
const SanityChecks = require('./sanityChecks')
|
|
19
|
+
const { Utils, Captcha } = require('./utils')
|
|
20
|
+
|
|
21
|
+
const Account = require('./api/account')
|
|
22
|
+
const User = require('./api/user')
|
|
23
|
+
const Track = require('./api/track')
|
|
24
|
+
const Playlist = require('./api/playlist')
|
|
25
|
+
const File = require('./api/file')
|
|
26
|
+
const Rewards = require('./api/rewards')
|
|
27
|
+
const ServiceProvider = require('./api/serviceProvider')
|
|
28
|
+
const Web3 = require('./web3')
|
|
29
|
+
const SolanaUtils = require('./services/solanaWeb3Manager/utils')
|
|
30
|
+
|
|
31
|
+
const { Keypair } = require('@solana/web3.js')
|
|
32
|
+
const { PublicKey } = require('@solana/web3.js')
|
|
33
|
+
const {
|
|
34
|
+
RewardsAttester
|
|
35
|
+
} = require('./services/solanaWeb3Manager/rewardsAttester')
|
|
36
|
+
class AudiusLibs {
|
|
37
|
+
/**
|
|
38
|
+
* Configures a discovery provider wrapper
|
|
39
|
+
* @param {Set<string>?} whitelist whether or not to include only specified nodes (default no whitelist)
|
|
40
|
+
* @param {Set<string>?} blacklist whether or not to exclude specified nodes (default no blacklist)
|
|
41
|
+
* @param {number?} reselectTimeout timeout to clear locally cached discovery providers
|
|
42
|
+
* @param {(selection: string) => void?} selectionCallback invoked with the select discovery provider
|
|
43
|
+
* @param {object?} monitoringCallbacks callbacks to be invoked with metrics from requests sent to a service
|
|
44
|
+
* @param {function} monitoringCallbacks.request
|
|
45
|
+
* @param {function} monitoringCallbacks.healthCheck
|
|
46
|
+
* @param {number?} selectionRequestTimeout the amount of time (ms) an individual request should take before reselecting
|
|
47
|
+
* @param {number?} selectionRequestRetries the number of retries to a given discovery node we make before reselecting
|
|
48
|
+
* @param {number?} unhealthySlotDiffPlays the number of slots we would consider a discovery node unhealthy
|
|
49
|
+
* @param {number?} unhealthyBlockDiff the number of missed blocks after which we would consider a discovery node unhealthy
|
|
50
|
+
*/
|
|
51
|
+
static configDiscoveryProvider(
|
|
52
|
+
whitelist = null,
|
|
53
|
+
blacklist = null,
|
|
54
|
+
reselectTimeout = null,
|
|
55
|
+
selectionCallback = null,
|
|
56
|
+
monitoringCallbacks = {},
|
|
57
|
+
selectionRequestTimeout = null,
|
|
58
|
+
selectionRequestRetries = null,
|
|
59
|
+
unhealthySlotDiffPlays = null,
|
|
60
|
+
unhealthyBlockDiff = null
|
|
61
|
+
) {
|
|
62
|
+
return {
|
|
63
|
+
whitelist,
|
|
64
|
+
blacklist,
|
|
65
|
+
reselectTimeout,
|
|
66
|
+
selectionCallback,
|
|
67
|
+
monitoringCallbacks,
|
|
68
|
+
selectionRequestTimeout,
|
|
69
|
+
selectionRequestRetries,
|
|
70
|
+
unhealthySlotDiffPlays,
|
|
71
|
+
unhealthyBlockDiff
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Configures an identity service wrapper
|
|
77
|
+
* @param {string} url
|
|
78
|
+
* @param {boolean?} useHedgehogLocalStorage whether or not to read hedgehog entropy in local storage
|
|
79
|
+
*/
|
|
80
|
+
static configIdentityService(url, useHedgehogLocalStorage = true) {
|
|
81
|
+
return { url, useHedgehogLocalStorage }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Configures an identity service wrapper
|
|
86
|
+
* @param {string} url
|
|
87
|
+
*/
|
|
88
|
+
static configComstock(url) {
|
|
89
|
+
return { url }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Configures a creator node wrapper
|
|
94
|
+
* @param {string} fallbackUrl creator node endpoint to fall back to on requests
|
|
95
|
+
* @param {boolean} lazyConnect whether to delay connection to the node until the first
|
|
96
|
+
* request that requires a connection is made.
|
|
97
|
+
* @param {Set<string>?} passList whether or not to include only specified nodes (default null)
|
|
98
|
+
* @param {Set<string>?} blockList whether or not to exclude any nodes (default null)
|
|
99
|
+
* @param {object?} monitoringCallbacks callbacks to be invoked with metrics from requests sent to a service
|
|
100
|
+
* @param {function} monitoringCallbacks.request
|
|
101
|
+
* @param {function} monitoringCallbacks.healthCheck
|
|
102
|
+
*/
|
|
103
|
+
static configCreatorNode(
|
|
104
|
+
fallbackUrl,
|
|
105
|
+
lazyConnect = false,
|
|
106
|
+
passList = null,
|
|
107
|
+
blockList = null,
|
|
108
|
+
monitoringCallbacks = {}
|
|
109
|
+
) {
|
|
110
|
+
return {
|
|
111
|
+
fallbackUrl,
|
|
112
|
+
lazyConnect,
|
|
113
|
+
passList,
|
|
114
|
+
blockList,
|
|
115
|
+
monitoringCallbacks
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Configures an external web3 to use with Audius Libs (e.g. MetaMask)
|
|
121
|
+
* @param {string} registryAddress
|
|
122
|
+
* @param {Object} web3Provider equal to web.currentProvider
|
|
123
|
+
* @param {?number} networkId network chain id
|
|
124
|
+
* @param {?string} walletOverride wallet address to force use instead of the first wallet on the provided web3
|
|
125
|
+
* @param {?number} walletIndex if using a wallet returned from web3, pick the wallet at this index
|
|
126
|
+
*/
|
|
127
|
+
static async configExternalWeb3(
|
|
128
|
+
registryAddress,
|
|
129
|
+
web3Provider,
|
|
130
|
+
networkId,
|
|
131
|
+
walletOverride = null
|
|
132
|
+
) {
|
|
133
|
+
const web3Instance = await Utils.configureWeb3(web3Provider, networkId)
|
|
134
|
+
if (!web3Instance) {
|
|
135
|
+
throw new Error('External web3 incorrectly configured')
|
|
136
|
+
}
|
|
137
|
+
const wallets = await web3Instance.eth.getAccounts()
|
|
138
|
+
return {
|
|
139
|
+
registryAddress,
|
|
140
|
+
useExternalWeb3: true,
|
|
141
|
+
externalWeb3Config: {
|
|
142
|
+
web3: web3Instance,
|
|
143
|
+
ownerWallet: walletOverride || wallets[0]
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Configures an internal web3 to use (via Hedgehog)
|
|
150
|
+
* @param {string} registryAddress
|
|
151
|
+
* @param {string | Web3 | Array<string>} providers web3 provider endpoint(s)
|
|
152
|
+
*/
|
|
153
|
+
static configInternalWeb3(registryAddress, providers, privateKey) {
|
|
154
|
+
let providerList
|
|
155
|
+
if (typeof providers === 'string') {
|
|
156
|
+
providerList = providers.split(',')
|
|
157
|
+
} else if (providers instanceof Web3) {
|
|
158
|
+
providerList = [providers]
|
|
159
|
+
} else if (Array.isArray(providers)) {
|
|
160
|
+
providerList = providers
|
|
161
|
+
} else {
|
|
162
|
+
throw new Error(
|
|
163
|
+
'Providers must be of type string, Array, or Web3 instance'
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
registryAddress,
|
|
169
|
+
useExternalWeb3: false,
|
|
170
|
+
internalWeb3Config: {
|
|
171
|
+
web3ProviderEndpoints: providerList,
|
|
172
|
+
privateKey
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Configures an eth web3
|
|
179
|
+
* @param {string} tokenAddress
|
|
180
|
+
* @param {string} registryAddress
|
|
181
|
+
* @param {string | Web3 | Array<string>} providers web3 provider endpoint(s)
|
|
182
|
+
* @param {string?} ownerWallet optional owner wallet to establish who we are sending transactions on behalf of
|
|
183
|
+
* @param {string?} claimDistributionContractAddress
|
|
184
|
+
* @param {string?} wormholeContractAddress
|
|
185
|
+
*/
|
|
186
|
+
static configEthWeb3(
|
|
187
|
+
tokenAddress,
|
|
188
|
+
registryAddress,
|
|
189
|
+
providers,
|
|
190
|
+
ownerWallet,
|
|
191
|
+
claimDistributionContractAddress,
|
|
192
|
+
wormholeContractAddress
|
|
193
|
+
) {
|
|
194
|
+
let providerList
|
|
195
|
+
if (typeof providers === 'string') {
|
|
196
|
+
providerList = providers.split(',')
|
|
197
|
+
} else if (providers instanceof Web3) {
|
|
198
|
+
providerList = [providers]
|
|
199
|
+
} else if (Array.isArray(providers)) {
|
|
200
|
+
providerList = providers
|
|
201
|
+
} else {
|
|
202
|
+
throw new Error(
|
|
203
|
+
'Providers must be of type string, Array, or Web3 instance'
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
tokenAddress,
|
|
209
|
+
registryAddress,
|
|
210
|
+
providers: providerList,
|
|
211
|
+
ownerWallet,
|
|
212
|
+
claimDistributionContractAddress,
|
|
213
|
+
wormholeContractAddress
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Configures wormhole
|
|
219
|
+
* @param {Object} config
|
|
220
|
+
* @param {string | Array<string>} config.rpcHosts
|
|
221
|
+
* @param {string} config.solBridgeAddress
|
|
222
|
+
* @param {string} config.solTokenBridgeAddress
|
|
223
|
+
* @param {string} config.ethBridgeAddress
|
|
224
|
+
* @param {string} config.ethTokenBridgeAddress
|
|
225
|
+
*/
|
|
226
|
+
static configWormhole({
|
|
227
|
+
rpcHosts,
|
|
228
|
+
solBridgeAddress,
|
|
229
|
+
solTokenBridgeAddress,
|
|
230
|
+
ethBridgeAddress,
|
|
231
|
+
ethTokenBridgeAddress
|
|
232
|
+
}) {
|
|
233
|
+
let rpcHostList
|
|
234
|
+
if (typeof rpcHosts === 'string') {
|
|
235
|
+
rpcHostList = rpcHosts.split(',')
|
|
236
|
+
} else if (Array.isArray(rpcHosts)) {
|
|
237
|
+
rpcHostList = rpcHosts
|
|
238
|
+
} else {
|
|
239
|
+
throw new Error('rpcHosts must be of type string or Array')
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
rpcHosts: rpcHostList,
|
|
243
|
+
solBridgeAddress,
|
|
244
|
+
solTokenBridgeAddress,
|
|
245
|
+
ethBridgeAddress,
|
|
246
|
+
ethTokenBridgeAddress
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Configures a solana web3
|
|
252
|
+
* @param {Object} config
|
|
253
|
+
* @param {string} config.solanaClusterEndpoint the RPC endpoint to make requests against
|
|
254
|
+
* @param {string} config.mintAddress wAudio mint address
|
|
255
|
+
* @param {string} solanaTokenAddress native solana token program
|
|
256
|
+
* @param {string} claimableTokenPDA the generated program derived address we use so our
|
|
257
|
+
* bank program can take ownership of accounts
|
|
258
|
+
* @param {string} feePayerAddress address for the fee payer for transactions
|
|
259
|
+
* @param {string} claimableTokenProgramAddress address of the audius user bank program
|
|
260
|
+
* @param {string} rewardsManagerProgramId address for the Rewards Manager program
|
|
261
|
+
* @param {string} rewardsManagerProgramPDA Rewards Manager PDA
|
|
262
|
+
* @param {string} rewardsManagerTokenPDA The PDA of the rewards manager funds holder account
|
|
263
|
+
* @param {boolean} useRelay Whether to use identity as a relay or submit transactions locally
|
|
264
|
+
* @param {Uint8Array} feePayerSecretKeys fee payer secret keys, if client wants to switch between different fee payers during relay
|
|
265
|
+
* @param {number} confirmationTimeout solana web3 connection confirmationTimeout in ms
|
|
266
|
+
* @param {PublicKey|string} audiusDataAdminStorageKeypairPublicKey admin storage PK for audius-data program
|
|
267
|
+
* @param {PublicKey|string} audiusDataProgramId program ID for the audius-data Anchor program
|
|
268
|
+
* @param {Idl} audiusDataIdl IDL for the audius-data Anchor program.
|
|
269
|
+
*/
|
|
270
|
+
static configSolanaWeb3({
|
|
271
|
+
solanaClusterEndpoint,
|
|
272
|
+
mintAddress,
|
|
273
|
+
solanaTokenAddress,
|
|
274
|
+
claimableTokenPDA,
|
|
275
|
+
feePayerAddress,
|
|
276
|
+
claimableTokenProgramAddress,
|
|
277
|
+
rewardsManagerProgramId,
|
|
278
|
+
rewardsManagerProgramPDA,
|
|
279
|
+
rewardsManagerTokenPDA,
|
|
280
|
+
useRelay,
|
|
281
|
+
feePayerSecretKeys,
|
|
282
|
+
confirmationTimeout,
|
|
283
|
+
audiusDataAdminStorageKeypairPublicKey,
|
|
284
|
+
audiusDataProgramId,
|
|
285
|
+
audiusDataIdl
|
|
286
|
+
}) {
|
|
287
|
+
if (audiusDataAdminStorageKeypairPublicKey instanceof String) {
|
|
288
|
+
audiusDataAdminStorageKeypairPublicKey = new PublicKey(
|
|
289
|
+
audiusDataAdminStorageKeypairPublicKey
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
if (audiusDataProgramId instanceof String) {
|
|
293
|
+
audiusDataProgramId = new PublicKey(audiusDataProgramId)
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
solanaClusterEndpoint,
|
|
297
|
+
mintAddress,
|
|
298
|
+
solanaTokenAddress,
|
|
299
|
+
claimableTokenPDA,
|
|
300
|
+
feePayerAddress,
|
|
301
|
+
claimableTokenProgramAddress,
|
|
302
|
+
rewardsManagerProgramId,
|
|
303
|
+
rewardsManagerProgramPDA,
|
|
304
|
+
rewardsManagerTokenPDA,
|
|
305
|
+
useRelay,
|
|
306
|
+
feePayerKeypairs: feePayerSecretKeys
|
|
307
|
+
? feePayerSecretKeys.map((key) => Keypair.fromSecretKey(key))
|
|
308
|
+
: null,
|
|
309
|
+
confirmationTimeout,
|
|
310
|
+
audiusDataAdminStorageKeypairPublicKey,
|
|
311
|
+
audiusDataProgramId,
|
|
312
|
+
audiusDataIdl
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Configures a solana audius-data
|
|
318
|
+
* @param {Object} config
|
|
319
|
+
* @param {string} config.programId Program ID of the audius data program
|
|
320
|
+
* @param {string} config.adminAccount Public Key of admin account
|
|
321
|
+
*/
|
|
322
|
+
static configSolanaAudiusData({ programId, adminAccount }) {
|
|
323
|
+
return {
|
|
324
|
+
programId,
|
|
325
|
+
adminAccount
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Constructs an Audius Libs instance with configs.
|
|
331
|
+
* Unless default-valued, all configs are optional.
|
|
332
|
+
* @example
|
|
333
|
+
* const audius = AudiusLibs({
|
|
334
|
+
* discoveryProviderConfig: configDiscoveryProvider(),
|
|
335
|
+
* creatorNodeConfig: configCreatorNode('https://my-creator.node')
|
|
336
|
+
* })
|
|
337
|
+
* await audius.init()
|
|
338
|
+
*/
|
|
339
|
+
constructor({
|
|
340
|
+
web3Config,
|
|
341
|
+
ethWeb3Config,
|
|
342
|
+
solanaWeb3Config,
|
|
343
|
+
solanaAudiusDataConfig,
|
|
344
|
+
identityServiceConfig,
|
|
345
|
+
discoveryProviderConfig,
|
|
346
|
+
creatorNodeConfig,
|
|
347
|
+
comstockConfig,
|
|
348
|
+
wormholeConfig,
|
|
349
|
+
captchaConfig,
|
|
350
|
+
isServer,
|
|
351
|
+
logger = console,
|
|
352
|
+
isDebug = false,
|
|
353
|
+
preferHigherPatchForPrimary = true,
|
|
354
|
+
preferHigherPatchForSecondaries = true
|
|
355
|
+
}) {
|
|
356
|
+
// set version
|
|
357
|
+
|
|
358
|
+
this.version = packageJSON.version
|
|
359
|
+
|
|
360
|
+
this.ethWeb3Config = ethWeb3Config
|
|
361
|
+
this.web3Config = web3Config
|
|
362
|
+
this.solanaWeb3Config = solanaWeb3Config
|
|
363
|
+
this.solanaAudiusDataConfig = solanaAudiusDataConfig
|
|
364
|
+
this.identityServiceConfig = identityServiceConfig
|
|
365
|
+
this.creatorNodeConfig = creatorNodeConfig
|
|
366
|
+
this.discoveryProviderConfig = discoveryProviderConfig
|
|
367
|
+
this.comstockConfig = comstockConfig
|
|
368
|
+
this.wormholeConfig = wormholeConfig
|
|
369
|
+
this.captchaConfig = captchaConfig
|
|
370
|
+
this.isServer = isServer
|
|
371
|
+
this.isDebug = isDebug
|
|
372
|
+
this.logger = logger
|
|
373
|
+
|
|
374
|
+
this.AudiusABIDecoder = AudiusABIDecoder
|
|
375
|
+
this.Utils = Utils
|
|
376
|
+
|
|
377
|
+
// Services to initialize. Initialized in .init().
|
|
378
|
+
this.userStateManager = null
|
|
379
|
+
this.identityService = null
|
|
380
|
+
this.hedgehog = null
|
|
381
|
+
this.discoveryProvider = null
|
|
382
|
+
this.ethWeb3Manager = null
|
|
383
|
+
this.ethContracts = null
|
|
384
|
+
this.web3Manager = null
|
|
385
|
+
this.solanaWeb3Manager = null
|
|
386
|
+
this.anchorAudiusData = null
|
|
387
|
+
this.contracts = null
|
|
388
|
+
this.creatorNode = null
|
|
389
|
+
|
|
390
|
+
// API
|
|
391
|
+
this.Account = null
|
|
392
|
+
this.User = null
|
|
393
|
+
this.Track = null
|
|
394
|
+
this.Playlist = null
|
|
395
|
+
this.File = null
|
|
396
|
+
this.Rewards = null
|
|
397
|
+
|
|
398
|
+
this.preferHigherPatchForPrimary = preferHigherPatchForPrimary
|
|
399
|
+
this.preferHigherPatchForSecondaries = preferHigherPatchForSecondaries
|
|
400
|
+
|
|
401
|
+
// Schemas
|
|
402
|
+
const schemaValidator = new SchemaValidator()
|
|
403
|
+
schemaValidator.init()
|
|
404
|
+
this.schemas = schemaValidator.getSchemas()
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** Init services based on presence of a relevant config. */
|
|
408
|
+
async init() {
|
|
409
|
+
this.userStateManager = new UserStateManager()
|
|
410
|
+
// Config external web3 is an async function, so await it here in case it needs to be
|
|
411
|
+
this.web3Config = await this.web3Config
|
|
412
|
+
|
|
413
|
+
/** Captcha */
|
|
414
|
+
if (this.captchaConfig) {
|
|
415
|
+
this.captcha = new Captcha(this.captchaConfig)
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** Identity Service */
|
|
419
|
+
if (this.identityServiceConfig) {
|
|
420
|
+
this.identityService = new IdentityService({
|
|
421
|
+
identityServiceEndpoint: this.identityServiceConfig.url,
|
|
422
|
+
captcha: this.captcha
|
|
423
|
+
})
|
|
424
|
+
const hedgehogService = new Hedgehog({
|
|
425
|
+
identityService: this.identityService,
|
|
426
|
+
useLocalStorage: this.identityServiceConfig.useHedgehogLocalStorage
|
|
427
|
+
})
|
|
428
|
+
this.hedgehog = hedgehogService.instance
|
|
429
|
+
} else if (this.web3Config && !this.web3Config.useExternalWeb3) {
|
|
430
|
+
throw new Error('Identity Service required for internal Web3')
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/** Web3 Managers */
|
|
434
|
+
if (this.ethWeb3Config) {
|
|
435
|
+
this.ethWeb3Manager = new EthWeb3Manager({
|
|
436
|
+
web3Config: this.ethWeb3Config,
|
|
437
|
+
identityService: this.identityService,
|
|
438
|
+
hedgehog: this.hedgehog
|
|
439
|
+
})
|
|
440
|
+
}
|
|
441
|
+
if (this.web3Config) {
|
|
442
|
+
this.web3Manager = new Web3Manager({
|
|
443
|
+
web3Config: this.web3Config,
|
|
444
|
+
identityService: this.identityService,
|
|
445
|
+
hedgehog: this.hedgehog,
|
|
446
|
+
isServer: this.isServer
|
|
447
|
+
})
|
|
448
|
+
await this.web3Manager.init()
|
|
449
|
+
if (this.identityService) {
|
|
450
|
+
this.identityService.setWeb3Manager(this.web3Manager)
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
if (this.solanaWeb3Config) {
|
|
454
|
+
this.solanaWeb3Manager = new SolanaWeb3Manager(
|
|
455
|
+
this.solanaWeb3Config,
|
|
456
|
+
this.identityService,
|
|
457
|
+
this.web3Manager
|
|
458
|
+
)
|
|
459
|
+
await this.solanaWeb3Manager.init()
|
|
460
|
+
}
|
|
461
|
+
if (this.solanaWeb3Manager && this.solanaAudiusDataConfig) {
|
|
462
|
+
this.solanaAudiusData = new SolanaAudiusData(
|
|
463
|
+
this.solanaAudiusDataConfig,
|
|
464
|
+
this.solanaWeb3Manager,
|
|
465
|
+
this.web3Manager
|
|
466
|
+
)
|
|
467
|
+
await this.solanaAudiusData.init()
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** Contracts - Eth and Data Contracts */
|
|
471
|
+
const contractsToInit = []
|
|
472
|
+
if (this.ethWeb3Manager) {
|
|
473
|
+
this.ethContracts = new EthContracts({
|
|
474
|
+
ethWeb3Manager: this.ethWeb3Manager,
|
|
475
|
+
tokenContractAddress: this.ethWeb3Config
|
|
476
|
+
? this.ethWeb3Config.tokenAddress
|
|
477
|
+
: null,
|
|
478
|
+
registryAddress: this.ethWeb3Config
|
|
479
|
+
? this.ethWeb3Config.registryAddress
|
|
480
|
+
: null,
|
|
481
|
+
claimDistributionContractAddress:
|
|
482
|
+
(this.ethWeb3Config &&
|
|
483
|
+
this.ethWeb3Config.claimDistributionContractAddress) ||
|
|
484
|
+
null,
|
|
485
|
+
wormholeContractAddress:
|
|
486
|
+
(this.ethWeb3Config && this.ethWeb3Config.wormholeContractAddress) ||
|
|
487
|
+
null,
|
|
488
|
+
isServer: this.isServer,
|
|
489
|
+
logger: this.logger,
|
|
490
|
+
isDebug: this.isDebug
|
|
491
|
+
})
|
|
492
|
+
contractsToInit.push(this.ethContracts.init())
|
|
493
|
+
}
|
|
494
|
+
if (this.web3Manager) {
|
|
495
|
+
this.contracts = new AudiusContracts(
|
|
496
|
+
this.web3Manager,
|
|
497
|
+
this.web3Config ? this.web3Config.registryAddress : null,
|
|
498
|
+
this.isServer,
|
|
499
|
+
this.logger
|
|
500
|
+
)
|
|
501
|
+
contractsToInit.push(this.contracts.init())
|
|
502
|
+
}
|
|
503
|
+
await Promise.all(contractsToInit)
|
|
504
|
+
if (
|
|
505
|
+
this.wormholeConfig &&
|
|
506
|
+
this.ethWeb3Manager &&
|
|
507
|
+
this.ethContracts &&
|
|
508
|
+
this.solanaWeb3Manager
|
|
509
|
+
) {
|
|
510
|
+
this.wormholeClient = new Wormhole(
|
|
511
|
+
this.hedgehog,
|
|
512
|
+
this.ethWeb3Manager,
|
|
513
|
+
this.ethContracts,
|
|
514
|
+
this.identityService,
|
|
515
|
+
this.solanaWeb3Manager,
|
|
516
|
+
this.wormholeConfig.rpcHosts,
|
|
517
|
+
this.wormholeConfig.solBridgeAddress,
|
|
518
|
+
this.wormholeConfig.solTokenBridgeAddress,
|
|
519
|
+
this.wormholeConfig.ethBridgeAddress,
|
|
520
|
+
this.wormholeConfig.ethTokenBridgeAddress,
|
|
521
|
+
this.isServer
|
|
522
|
+
)
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/** Discovery Provider */
|
|
526
|
+
if (this.discoveryProviderConfig) {
|
|
527
|
+
this.discoveryProvider = new DiscoveryProvider({
|
|
528
|
+
whitelist: this.discoveryProviderConfig.whitelist,
|
|
529
|
+
blacklist: this.discoveryProviderConfig.blacklist,
|
|
530
|
+
userStateManager: this.userStateManager,
|
|
531
|
+
ethContracts: this.ethContracts,
|
|
532
|
+
web3Manager: this.web3Manager,
|
|
533
|
+
reselectTimeout: this.discoveryProviderConfig.reselectTimeout,
|
|
534
|
+
selectionCallback: this.discoveryProviderConfig.selectionCallback,
|
|
535
|
+
monitoringCallbacks: this.discoveryProviderConfig.monitoringCallbacks,
|
|
536
|
+
selectionRequestTimeout:
|
|
537
|
+
this.discoveryProviderConfig.selectionRequestTimeout,
|
|
538
|
+
selectionRequestRetries:
|
|
539
|
+
this.discoveryProviderConfig.selectionRequestRetries,
|
|
540
|
+
unhealthySlothDiffPlays:
|
|
541
|
+
this.discoveryProviderConfig.unhealthySlotDiffPlays,
|
|
542
|
+
unhealthBlockDiff: this.discoveryProviderConfig.unhealthyBlockDiff
|
|
543
|
+
})
|
|
544
|
+
await this.discoveryProvider.init()
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** Creator Node */
|
|
548
|
+
if (this.creatorNodeConfig) {
|
|
549
|
+
const currentUser = this.userStateManager.getCurrentUser()
|
|
550
|
+
const creatorNodeEndpoint = currentUser
|
|
551
|
+
? CreatorNode.getPrimary(currentUser.creator_node_endpoint) ||
|
|
552
|
+
this.creatorNodeConfig.fallbackUrl
|
|
553
|
+
: this.creatorNodeConfig.fallbackUrl
|
|
554
|
+
|
|
555
|
+
this.creatorNode = new CreatorNode(
|
|
556
|
+
this.web3Manager,
|
|
557
|
+
creatorNodeEndpoint,
|
|
558
|
+
this.isServer,
|
|
559
|
+
this.userStateManager,
|
|
560
|
+
this.creatorNodeConfig.lazyConnect,
|
|
561
|
+
this.schemas,
|
|
562
|
+
this.creatorNodeConfig.passList,
|
|
563
|
+
this.creatorNodeConfig.blockList,
|
|
564
|
+
this.creatorNodeConfig.monitoringCallbacks
|
|
565
|
+
)
|
|
566
|
+
await this.creatorNode.init()
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/** Comstock */
|
|
570
|
+
if (this.comstockConfig) {
|
|
571
|
+
this.comstock = new Comstock(this.comstockConfig.url)
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// Initialize apis
|
|
575
|
+
const services = [
|
|
576
|
+
this.userStateManager,
|
|
577
|
+
this.identityService,
|
|
578
|
+
this.hedgehog,
|
|
579
|
+
this.discoveryProvider,
|
|
580
|
+
this.web3Manager,
|
|
581
|
+
this.contracts,
|
|
582
|
+
this.ethWeb3Manager,
|
|
583
|
+
this.ethContracts,
|
|
584
|
+
this.solanaWeb3Manager,
|
|
585
|
+
this.anchorAudiusData,
|
|
586
|
+
this.wormholeClient,
|
|
587
|
+
this.creatorNode,
|
|
588
|
+
this.comstock,
|
|
589
|
+
this.captcha,
|
|
590
|
+
this.isServer,
|
|
591
|
+
this.logger
|
|
592
|
+
]
|
|
593
|
+
this.ServiceProvider = new ServiceProvider(...services)
|
|
594
|
+
this.User = new User(
|
|
595
|
+
this.ServiceProvider,
|
|
596
|
+
this.preferHigherPatchForPrimary,
|
|
597
|
+
this.preferHigherPatchForSecondaries,
|
|
598
|
+
...services
|
|
599
|
+
)
|
|
600
|
+
this.Account = new Account(this.User, ...services)
|
|
601
|
+
this.Track = new Track(...services)
|
|
602
|
+
this.Playlist = new Playlist(...services)
|
|
603
|
+
this.File = new File(this.User, ...services)
|
|
604
|
+
this.Rewards = new Rewards(this.ServiceProvider, ...services)
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// This is needed to ensure default and named exports are handled correctly by rollup
|
|
609
|
+
// https://github.com/rollup/plugins/tree/master/packages/commonjs#defaultismoduleexports
|
|
610
|
+
// exports.__esModule = true
|
|
611
|
+
|
|
612
|
+
module.exports = AudiusLibs
|
|
613
|
+
|
|
614
|
+
module.exports.AudiusABIDecoder = AudiusABIDecoder
|
|
615
|
+
module.exports.Utils = Utils
|
|
616
|
+
module.exports.SolanaUtils = SolanaUtils
|
|
617
|
+
module.exports.SanityChecks = SanityChecks
|
|
618
|
+
module.exports.RewardsAttester = RewardsAttester
|
|
619
|
+
module.exports.CreatorNode = CreatorNode
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const { CreatorNode } = require('../services/creatorNode')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Add secondary creator nodes for a user if they don't have any
|
|
5
|
+
* Goal: Make it so users always have a replica set
|
|
6
|
+
*/
|
|
7
|
+
const addSecondaries = async (libs) => {
|
|
8
|
+
console.debug('Sanity Check - addSecondaries')
|
|
9
|
+
const user = libs.userStateManager.getCurrentUser()
|
|
10
|
+
|
|
11
|
+
if (!user || !user.is_creator) return
|
|
12
|
+
|
|
13
|
+
const primary = CreatorNode.getPrimary(user.creator_node_endpoint)
|
|
14
|
+
const secondaries = CreatorNode.getSecondaries(user.creator_node_endpoint)
|
|
15
|
+
|
|
16
|
+
// Get current endpoints and check if we don't have enough secondaries
|
|
17
|
+
if (secondaries.length < 2) {
|
|
18
|
+
console.debug(`Sanity Check - addSecondaries - User has only ${secondaries.length}`)
|
|
19
|
+
|
|
20
|
+
// Find new healthy secondaries
|
|
21
|
+
const currentEndpoints = CreatorNode.getEndpoints(user.creator_node_endpoint)
|
|
22
|
+
const services = await libs.ServiceProvider.getSelectableCreatorNodes(
|
|
23
|
+
/* whitelist */ null,
|
|
24
|
+
/* blacklist */ new Set(currentEndpoints)
|
|
25
|
+
)
|
|
26
|
+
console.debug(`Sanity Check - addSecondaries - found services ${JSON.stringify(services)}`)
|
|
27
|
+
const newSecondaries = Object.keys(services)
|
|
28
|
+
.slice(0, 2 - secondaries.length)
|
|
29
|
+
|
|
30
|
+
// Combine primary, current secondaries, and new secondaries
|
|
31
|
+
const newEndpoints = [primary, ...secondaries, ...newSecondaries]
|
|
32
|
+
|
|
33
|
+
const newMetadata = { ...user }
|
|
34
|
+
newMetadata.creator_node_endpoint = newEndpoints.join(',')
|
|
35
|
+
console.debug(`Sanity Check - addSecondaries - new nodes ${newMetadata.creator_node_endpoint}`)
|
|
36
|
+
await libs.User.updateCreator(user.user_id, newMetadata)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = addSecondaries
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const assignReplicaSetIfNecessary = async (libs) => {
|
|
2
|
+
try {
|
|
3
|
+
await libs.User.assignReplicaSetIfNecessary()
|
|
4
|
+
} catch (e) {
|
|
5
|
+
// If sanity check fails, do not block main thread and log error
|
|
6
|
+
console.error(e.message)
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = assignReplicaSetIfNecessary
|