@@ -12,73 +12,25 @@ import Outpoint from './outpoint';
12
12
import Period from './period' ;
13
13
import Tx from './transaction' ;
14
14
15
- function getLowerCase ( value ) {
16
- if ( value ) {
17
- return value . toLowerCase ( ) ;
18
- }
19
- return value ;
20
- }
21
-
22
15
const fromRaw = u => ( {
23
16
output : u . output ,
24
17
outpoint : Outpoint . fromRaw ( u . outpoint ) ,
25
18
} ) ;
26
19
27
- export class LeapEthers {
28
- /**
29
- * @param { import("ethers").providers.JsonRpcProvider } provider
30
- */
31
- constructor ( provider ) {
32
- this . provider = provider ;
33
- }
34
-
35
- getUnspent ( ...params ) {
36
- return this . provider
37
- . send ( 'plasma_unspent' , params . map ( getLowerCase ) )
38
- . then ( unspent => unspent . map ( fromRaw ) ) ;
39
- }
40
-
41
- getUnspentByAddress ( ...params ) {
42
- return this . getUnspent ( params ) ;
43
- }
44
-
45
- getUnspentAll ( ) {
46
- return this . provider
47
- . send ( 'plasma_unspent' , [ ] )
48
- . then ( unspent => unspent . map ( fromRaw ) ) ;
49
- }
50
-
51
- getColor ( ...params ) {
52
- return this . provider . send ( 'plasma_getColor' , params . map ( getLowerCase ) ) ;
53
- }
54
-
55
- getColors ( ) {
56
- return this . provider . send ( 'plasma_getColors' , [ ] ) ;
57
- }
58
-
59
- status ( ) {
60
- return this . provider . send ( 'plasma_status' , [ ] ) ;
61
- }
62
-
63
- getConfig ( ) {
64
- return this . provider . send ( 'plasma_getConfig' , [ ] ) ;
65
- }
20
+ const paddedParams = ( params ) => {
21
+ const hasCb = typeof params [ params . length - 1 ] === 'function' ;
22
+ const paramCount = hasCb ? params . length - 1 : params . length ;
66
23
67
- getValidatorInfo ( ) {
68
- return this . provider . send ( 'validator_getAddress ', [ ] ) ;
24
+ if ( paramCount === 0 ) { // getUnspent()
25
+ return [ ' ', '' , ... params ] ;
69
26
}
70
27
71
- checkSpendingCondition ( tx ) {
72
- return this . provider . send ( 'checkSpendingCondition' , [ tx . hex ( ) ] ) . then ( ( { error, outputs } ) => ( {
73
- error,
74
- outputs : outputs . map ( Output . fromJSON ) ,
75
- } ) ) ;
28
+ if ( paramCount === 1 ) { // getUnspent(address)
29
+ return [ params [ 0 ] , '' , ...params . splice ( 1 ) ] ;
76
30
}
77
31
78
- getPeriodByBlockHeight ( blockHeight ) {
79
- return this . provider . send ( 'plasma_getPeriodByBlockHeight' , [ blockHeight ] ) ;
80
- }
81
- }
32
+ return params ; // getUnspent(address, color)
33
+ } ;
82
34
83
35
export function extendWeb3 ( web3Instance ) {
84
36
// `_extend` for web3 0.2x.x, `extend` for 1.x
@@ -104,17 +56,7 @@ export function extendWeb3(web3Instance) {
104
56
methods : [
105
57
new extend . Method ( {
106
58
...getUnspent ,
107
- name : 'getUnspentByAddress' ,
108
- params : 1 ,
109
- } ) ,
110
- new extend . Method ( {
111
- ...getUnspent ,
112
- name : 'getUnspentByAddressColor' ,
113
- } ) ,
114
- new extend . Method ( {
115
- ...getUnspent ,
116
- name : 'getUnspentAll' ,
117
- params : 0 ,
59
+ name : '_getUnspent' ,
118
60
} ) ,
119
61
new extend . Method ( {
120
62
name : 'getColor' ,
@@ -173,16 +115,24 @@ export function extendWeb3(web3Instance) {
173
115
] ,
174
116
} ) ;
175
117
176
- web3Instance . getUnspent = ( ...params ) => {
177
- const last = params [ params . length - 1 ] ;
178
- const hasCb = typeof last === 'function' ;
179
- if ( params . length === ( hasCb ? 2 : 1 ) ) {
180
- return web3Instance . getUnspentByAddress ( ...params ) ;
181
- }
118
+ web3Instance . getUnspentAll = ( ...params ) => {
119
+ console . warn ( 'DEPRECATED: use getUnspent() instead' ) ; // eslint-disable-line no-console
120
+ return web3Instance . getUnspent ( ...params ) ;
121
+ } ;
182
122
183
- return web3Instance . getUnspentByAddressColor ( ...params ) ;
123
+ web3Instance . getUnspentByAddress = ( ...params ) => {
124
+ console . warn ( 'DEPRECATED: use getUnspent(address) instead' ) ; // eslint-disable-line no-console
125
+ return web3Instance . getUnspent ( ...params ) ;
184
126
} ;
185
127
128
+ web3Instance . getUnspentByAddressColor = ( ...params ) => {
129
+ console . warn ( 'DEPRECATED: use getUnspent(address, color) instead' ) ; // eslint-disable-line no-console
130
+ return web3Instance . getUnspent ( ...params ) ;
131
+ } ;
132
+
133
+ web3Instance . getUnspent = ( ...params ) =>
134
+ web3Instance . _getUnspent ( ...paddedParams ( params ) ) ; // eslint-disable-line no-underscore-dangle
135
+
186
136
return web3Instance ;
187
137
}
188
138
@@ -234,7 +184,7 @@ export function getTxWithYoungestBlock(txs) {
234
184
* Returns the youngest input for a given tx.
235
185
*
236
186
* Youngest input is the one which references tx with biggest block number.
237
- * @param {ExtendedWeb3 } plasma instance of Leap Web3
187
+ * @param {ExtendedWeb3|LeapProvider } plasma instance of Leap Web3
238
188
* @param {Tx } tx
239
189
* @returns {Promise<InputTx> } promise that resolves to youngest input tx and its index
240
190
*/
@@ -247,7 +197,7 @@ export function getYoungestInputTx(plasma, tx) {
247
197
/**
248
198
* Creates proof of period inclusion for a given tx
249
199
*
250
- * @param {ExtendedWeb3 } plasma instance of Leap Web3
200
+ * @param {ExtendedWeb3|LeapProvider } plasma instance of Leap Web3
251
201
* @param {LeapTransaction } tx
252
202
* @returns {Promise<Proof> } promise that resolves to period inclusion proof
253
203
*/
@@ -314,10 +264,12 @@ const send = (plasma, txHex) => {
314
264
* Sends a signed transaction to the node
315
265
*
316
266
* @param {ExtendedWeb3 } plasma instance of Leap Web3 or JSONRPCProvider of Ethers.js
317
- * @param {LeapTransaction } txHex - transaction to send
267
+ * @param {string } txHex - transaction to send
318
268
* @returns {Promise<Receipt> } promise that resolves to a transaction receipt
319
269
*/
320
270
export function sendSignedTransaction ( plasma , txHex ) {
271
+ // eslint-disable-next-line no-console
272
+ console . warn ( 'DEPRECATED: use Web3#sendSignedTransaction or LeapProvider#sendTransaction instead' ) ;
321
273
return send ( plasma , txHex ) . then ( ( resp ) => {
322
274
return awaitForReceipt ( resp , Promise . resolve ( ) , plasma , 0 ) ;
323
275
} ) ;
@@ -334,10 +286,10 @@ export function consolidateUTXOs(utxos) {
334
286
/**
335
287
* Returns outputs for spending condition tx
336
288
*
337
- * @param {ExtendedWeb3 | LeapEthers } plasma
338
- * @param {LeapTransaction } tx
289
+ * @param {ExtendedWeb3 | LeapProvider } plasma
290
+ * @param {Tx } tx
339
291
*
340
- * @returns {Promise<Output> }
292
+ * @returns {Promise<Array< Output> > }
341
293
*/
342
294
export function simulateSpendCond ( plasma , tx ) {
343
295
return plasma . checkSpendingCondition ( tx ) ;
0 commit comments