forked from cryptum-official/cryptum-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
122 lines (109 loc) · 3.7 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const { getWebhooksControllerInstance } = require('./src/features/webhooks/controller')
const { getWalletControllerInstance } = require('./src/features/wallet/controller')
const { getPricesControllerInstance } = require('./src/features/prices/controller')
const { getTransactionControllerInstance } = require('./src/features/transaction/controller')
const { getStakingControllerInstance } = require('./src/features/staking/controller')
const { getSwapControllerInstance } = require('./src/features/swap/controller')
const { getTokenControllerInstance } = require('./src/features/token/controller')
const { getNftControllerInstance } = require('./src/features/nft/controller')
const { getContractControllerInstance } = require('./src/features/contract/controller')
const { getLootBoxControllerInstance } = require('./src/features/lootBox/controller')
const { Protocol } = require('./src/services/blockchain/constants')
const { GenericException } = require('./src/errors')
const { getKmsControllerInstance } = require('./src/features/kms/controller')
/**
* @typedef {object} Config
* @property {'testnet'|'mainnet'} environment
* @property {string} apiKey
*/
class CryptumSDK {
/**
*
* @param {Config} config
*/
constructor(config) {
this.config = config
}
/**
* Method to get an controller to create, get and delete webhooks
*
* @returns an WebhooksController instance class to manipulate
*/
get webhook() { return this.getWebhooksController() }
getWebhooksController() {
return getWebhooksControllerInstance(this.config)
}
/**
* Method to get a controller to manipulate wallets
*
* @returns WalletController instance
*/
get wallet() { return this.getWalletController() }
getWalletController() {
return getWalletControllerInstance(this.config)
}
/**
* Method to get a controller to manipulate transactions
*
* @returns TransactionController instance
*/
get transaction() { return this.getTransactionController() }
getTransactionController() {
return getTransactionControllerInstance(this.config)
}
get staking() { return getStakingControllerInstance(this.config) }
/**
* Method to get a controller to manipulate transactions
* @param {Object} args
* @param {Protocol} args.protocol
* @returns TransactionController instance
*/
getStakingController({ protocol }) {
const controller = getStakingControllerInstance(this.config)
switch (protocol) {
case Protocol.CELO:
return controller.celo
default:
throw new GenericException('Invalid protocol')
}
}
/**
* Method to get a controller to manipulate prices
*
* @returns PricesController instance
*/
get prices() { return this.getPricesController() }
getPricesController() {
return getPricesControllerInstance(this.config)
}
/**
* Method to get a controller to manipulate swap
*
* @returns SwapController instance
*/
get swap() { return this.getSwapController() }
getSwapController() {
return getSwapControllerInstance(this.config)
}
get token() { return this.getTokenController() }
getTokenController() {
return getTokenControllerInstance(this.config)
}
get nft() { return this.getNftController() }
getNftController() {
return getNftControllerInstance(this.config)
}
get contract() { return this.getContractController() }
getContractController() {
return getContractControllerInstance(this.config)
}
get lootBox() { return this.getLootBoxController() }
getLootBoxController() {
return getLootBoxControllerInstance(this.config)
}
get kms() { return this.getKmsController() }
getKmsController() {
return getKmsControllerInstance(this.config)
}
}
module.exports = CryptumSDK