forked from urbit/azimuth-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecliptic.js
310 lines (274 loc) · 11 KB
/
ecliptic.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/**
* Ecliptic API
* @module ecliptic
*/
const internal = require('./internal/ecliptic');
const azimuth = require('./azimuth');
/**
* Get ecliptic contract owner.
* @param {Object} contracts - An Urbit contracts object.
* @return {Promise<String>} The owner address.
*/
module.exports.owner = internal.owner;
/**
* Get the amount of points owned by an address.
* @param {Object} contracts - An Urbit contracts object.
* @param {String} address - Owner's address.
* @return {Promise<Number>} Number of azimuth.
*/
module.exports.balanceOf = internal.balanceOf;
/**
* Get the current owner of a point.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} pointId - Point number.
* @return {Promise<String>} Owner's address.
*/
module.exports.ownerOf = internal.ownerOf;
/**
* Check if a point is active.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} pointId - Point number.
* @return {Promise<Bool>} true if point is active, false otherwise.
*/
module.exports.exists = internal.exists;
/**
* Get the transfer proxy for a point.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} pointId - Point number.
* @return {Promise<String>} The transfer proxy's address.
*/
module.exports.getApproved = internal.getApproved;
/**
* Check if an address is an operator for an owner.
* @param {Object} contracts - An Urbit contracts object.
* @param {String} owner - The owner's address.
* @param {String} operator - The operator's address.
* @return {Promise<Bool>} true if 'operator' is an operator for 'owner'.
*/
module.exports.isApprovedForAll = internal.isApprovedForAll;
/**
* Return the total number of children a point is allowed to spawn at some time.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} point - Point number.
* @param {Number} time - Time (uint256).
* @return {Promise<Number>} The spawn limit.
*/
module.exports.getSpawnLimit = internal.getSpawnLimit;
/**
* Check if a point can escape to a sponsor.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} point - Point number.
* @param {Number} sponsor - Sponsor's point number.
* @return {Promise<Bool>} True if point can escape, false otherwise.
*/
module.exports.canEscapeTo = internal.canEscapeTo;
/**
* Get the amount of children point can still spawn before hitting the limit.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} point - Point number.
* @return {Promise<Number>} The amount of children still spawnable from point.
*/
module.exports.getSpawnsRemaining = async function(contracts, point) {
const now = Math.floor(new Date().getTime() / 1000);
const count = await azimuth.getSpawnCount(contracts, point);
const limit = await internal.getSpawnLimit(contracts, point, now);
return limit - count;
}
/**
* Safely transfer a point between addresses (call recipient if it's a contract).
* @param {Object} contracts - An Urbit contracts object.
* @param {String} from - Sender's address.
* @param {String} to - Receiver's address.
* @param {Number} pointId - Point number.
* @return {Object} An unsigned transaction object.
*/
module.exports.safeTransferFrom = internal.safeTransferFrom;
/**
* Transfer a point between addresses (without notifying recipient contract).
* @param {Object} contracts - An Urbit contracts object.
* @param {String} from - Sender's address.
* @param {String} to - Receiver's address.
* @param {Number} pointId - Point number.
* @return {Object} An unsigned transaction object.
*/
module.exports.transferFrom = internal.transferFrom;
/**
* Allow an address to transfer ownership of a point.
* @param {Object} contracts - An Urbit contracts object.
* @param {String} approved - The approved address.
* @param {Number} pointId - Point number.
* @return {Object} An unsigned transaction object.
*/
module.exports.approve = internal.approve;
/**
* Allow or disallow an operator to transfer ownership of all points owned by
* the message sender.
* @param {Object} contracts - An Urbit contracts object.
* @param {Address} operator - The operator's address.
* @param {Bool} approved - Whether the operator is approved or not.
* @return {Object} An unsigned transaction object.
*/
module.exports.setApprovalForAll = internal.setApprovalForAll;
/**
* Configure the management address for a point owned by the message sender.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} point - The point to manage.
* @param {String} manager - The management address.
* @return {Object} An unsigned transaction object.
*/
module.exports.setManagementProxy = internal.setManagementProxy;
/**
* Configure a point with Urbit public keys, incrementing the point's continuity
* number if needed.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} point - Point number.
* @param {String} encryptionKey - The encryption key.
* @param {String} authenticationKey - The auth key.
* @param {Number} cryptoSuiteVersion - The crypto suite version.
* @param {Bool} discontinuous - True to increment the continuity number.
* @return {Object} An unsigned transaction object.
*/
module.exports.configureKeys = internal.configureKeys;
/**
* Spawn a point, giving ownership of it to the target address.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} point - A point number.
* @param {String} target - The target address.
* @return {Object} An unsigned transaction object.
*/
module.exports.spawn = internal.spawn;
/**
* Give an address the right to spawn points with the given prefix.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} prefix - A (prefix) point number.
* @param {String} address - The address to designate as a spawn proxy.
* @return {Object} An unsigned transaction object.
*/
module.exports.setSpawnProxy = internal.setSpawnProxy;
/**
* Transfer a point to a target address, optionally clearing all permissions
* data and keys.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} point - Point number.
* @param {String} address - The target address.
* @param {Bool} reset - True to reset point's keys.
* @return {Object} An unsigned transaction object.
*/
module.exports.transferPoint = internal.transferPoint;
/**
* Give an address the right to transfer the given point.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} prefix - Point number.
* @param {String} address - The address to designate as a transfer proxy.
* @return {Object} An unsigned transaction object.
*/
module.exports.setTransferProxy = internal.setTransferProxy;
/**
* Request escape from 'point' to 'sponsor'.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} point - Escapee's point number.
* @param {Number} sponsor - Sponsor's point number.
* @return {Object} An unsigned transaction object.
*/
module.exports.escape = internal.escape;
/**
* Cancel the currently set escape for a point.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} point - Escapee's point number.
* @return {Object} An unsigned transaction object.
*/
module.exports.cancelEscape = internal.cancelEscape;
/**
* As the sponsor, accept the escapee.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} escapee - Escapee's point number.
* @return {Object} An unsigned transaction object.
*/
module.exports.adopt = internal.adopt;
/**
* As the sponsor, reject the escapee's escape request.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} escapee - Escapee's point number.
* @return {Object} An unsigned transaction object.
*/
module.exports.reject = internal.reject;
/**
* As the sponsor, stop sponsoring the point.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} point - Point number.
* @return {Object} An unsigned transaction object.
*/
module.exports.detach = internal.detach;
/**
* Configure the voting proxy address for the galaxy.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} galaxy - Point number.
* @param {String} proxy - The proxy's address.
* @return {Object} An unsigned transaction object.
*/
module.exports.setVotingProxy = internal.setVotingProxy;
/**
* As a galaxy, start a poll for the ecliptic upgrade proposal.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} galaxy - A (galaxy) point number.
* @param {Object} proposal - The ecliptic upgrade proposal.
* @return {Object} An unsigned transaction object.
*/
module.exports.startUpgradePoll = internal.startUpgradePoll;
/**
* As a galaxy, start a poll for a proposal.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} galaxy - A (galaxy) point number.
* @param {String} proposal - The proposal document.
* @return {Object} An unsigned transaction object.
*/
module.exports.startDocumentPoll = internal.startDocumentPoll;
/**
* As a galaxy, cast a vote on the ecliptic upgrade proposal.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} galaxy - A (galaxy) point number.
* @param {Object} proposal - The upgrade proposal.
* @param {Bool} vote - True if yes, false otherwise.
* @return {Object} An unsigned transaction object.
*/
module.exports.castUpgradeVote = internal.castUpgradeVote;
/**
* As a galaxy, cast a vote on the proposal.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} galaxy - A (galaxy) point number.
* @param {String} proposal - The proposal document.
* @param {Bool} vote - True if yes, false otherwise.
* @return {Object} An unsigned transaction object.
*/
module.exports.castDocumentVote = internal.castDocumentVote;
/**
* Check whether the proposal has achieved majority, upgrading to it if so.
* @param {Object} contracts - An Urbit contracts object.
* @param {Object} proposal - The upgrade proposal.
* @return {Object} An unsigned transaction object.
*/
module.exports.updateUpgradePoll = internal.updateUpgradePoll;
/**
* Check whether the proposal has achieved majority.
* @param {Object} contracts - An Urbit contracts object.
* @param {Object} proposal - The proposal document.
* @return {Object} An unsigned transaction object.
*/
module.exports.updateDocumentPoll = internal.updateDocumentPoll;
/**
* Grant the target address ownership of the galaxy and register it for voting.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} galaxy - A (galaxy) point number.
* @param {String} target - The target address.
* @return {Object} An unsigned transaction object.
*/
module.exports.createGalaxy = internal.createGalaxy;
/**
* Set primary, secondary, adn tertiary DNS domains for the ecliptic.
* @param {Object} contracts - An Urbit contracts object.
* @param {String} primary - Primary DNS address.
* @param {String} secondary - Secondary DNS address.
* @param {String} tertiary - Tertiary DNS address.
* @return {Object} An unsigned transaction object.
*/
module.exports.setDnsDomains = internal.setDnsDomains;