Completed
Push — master ( f41849...8084fa )
by Adrian
01:23
created

FactomWalletApi::addEcOutput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
3
namespace AdrianMejias\FactomApi;
4
5
class FactomWalletApi extends FactomConnector
6
{
7
    /**
8
     * Example of an invalid method.
9
     *
10
     * @url https://docs.factom.com/api#errors45
11
     *
12
     * @return json { int code, string message }
13
     */
14
    public function errors()
15
    {
16
        $result = $this->callEndpoint('bad', 'GET');
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('bad', 'GET'); of type object|string adds the type string to the return on line 19 which is incompatible with the return type documented by AdrianMejias\FactomApi\FactomWalletApi::errors of type AdrianMejias\FactomApi\json.
Loading history...
17
18
        // return Result
19
        return $result;
20
    }
21
22
    /**
23
     * Retrieve the public and private parts of a Factoid or Entry Credit address stored in the wallet.
24
     *
25
     * @url https://docs.factom.com/api#address
26
     *
27
     * @return json { string public, string secret }
28
     */
29
    public function address(string $address)
30
    {
31
        $result = $this->callEndpoint('address', 'GET', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('add...address' => $address)); of type object|string adds the type string to the return on line 36 which is incompatible with the return type documented by AdrianMejias\FactomApi\FactomWalletApi::address of type AdrianMejias\FactomApi\json.
Loading history...
32
            'address' => $address,
33
        ]);
34
35
        // return Result
36
        return $result;
37
    }
38
39
    /**
40
     * Retrieve all of the Factoid and Entry Credit addresses stored in the wallet.
41
     *
42
     * @url https://docs.factom.com/api#all-address
43
     *
44
     * @return json { array addresses }
45
     */
46
    public function allAddress(string $address)
0 ignored issues
show
Unused Code introduced by
The parameter $address is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48
        $result = $this->callEndpoint('all-address', 'GET');
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('all-address', 'GET'); of type object|string adds the type string to the return on line 51 which is incompatible with the return type documented by AdrianMejias\FactomApi\FactomWalletApi::allAddress of type AdrianMejias\FactomApi\json.
Loading history...
49
50
        // return Result
51
        return $result;
52
    }
53
54
    /**
55
     * Create a new Entry Credit Address and store it in the wallet.
56
     *
57
     * @url https://docs.factom.com/api#generate-ec-address
58
     *
59
     * @return json { string public, string secret }
60
     */
61
    public function generateEcAddress()
62
    {
63
        $result = $this->callEndpoint('generate-ec-address', 'GET');
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('gen...te-ec-address', 'GET'); of type object|string adds the type string to the return on line 66 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...tApi::generateEcAddress of type AdrianMejias\FactomApi\json.
Loading history...
64
65
        // return Result
66
        return $result;
67
    }
68
69
    /**
70
     * Create a new Entry Credit Address and store it in the wallet.
71
     *
72
     * @url https://docs.factom.com/api#generate-factoid-address
73
     *
74
     * @return json { string public, string secret }
75
     */
76
    public function generateFactoidAddress()
77
    {
78
        $result = $this->callEndpoint('generate-factoid-address', 'GET');
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('gen...ctoid-address', 'GET'); of type object|string adds the type string to the return on line 81 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...:generateFactoidAddress of type AdrianMejias\FactomApi\json.
Loading history...
79
80
        // return Result
81
        return $result;
82
    }
83
84
    /**
85
     * Get the current hight of blocks that have been cached by the wallet while syncing.
86
     *
87
     * @url https://docs.factom.com/api#get-height
88
     *
89
     * @return json { int height }
90
     */
91
    public function getHeight()
92
    {
93
        $result = $this->callEndpoint('get-height', 'GET');
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('get-height', 'GET'); of type object|string adds the type string to the return on line 96 which is incompatible with the return type documented by AdrianMejias\FactomApi\FactomWalletApi::getHeight of type AdrianMejias\FactomApi\json.
Loading history...
94
95
        // return Result
96
        return $result;
97
    }
98
99
    /**
100
     * Import Factoid and/or Entry Credit address secret keys into the wallet.
101
     *
102
     * @url https://docs.factom.com/api#import-addresses
103
     *
104
     * @return json { array addresses }
105
     */
106
    public function importAddresses(string $addresses)
107
    {
108
        $result = $this->callEndpoint('addresses', 'GET', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('add...esses' => $addresses)); of type object|string adds the type string to the return on line 113 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...letApi::importAddresses of type AdrianMejias\FactomApi\json.
Loading history...
109
            'addresses' => $addresses,
110
        ]);
111
112
        // return Result
113
        return $result;
114
    }
115
116
    /**
117
     * Import a Koinify crowd sale address into the wallet.
118
     *
119
     * @url https://docs.factom.com/api#import-koinify
120
     *
121
     * @return json { string public, string secret }
122
     */
123
    public function importKoinify(string $words)
124
    {
125
        $result = $this->callEndpoint('import-koinify', 'GET', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('imp...ay('words' => $words)); of type object|string adds the type string to the return on line 130 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...alletApi::importKoinify of type AdrianMejias\FactomApi\json.
Loading history...
126
            'words' => $words,
127
        ]);
128
129
        // return Result
130
        return $result;
131
    }
132
133
    /**
134
     * Return the wallet seed and all addresses in the wallet for backup and offline storage.
135
     *
136
     * @url https://docs.factom.com/api#wallet-backup
137
     *
138
     * @return json { string wallet-seed, array addresses }
139
     */
140
    public function walletBackup()
141
    {
142
        $result = $this->callEndpoint('wallet-backup', 'GET');
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('wallet-backup', 'GET'); of type object|string adds the type string to the return on line 145 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...WalletApi::walletBackup of type AdrianMejias\FactomApi\json.
Loading history...
143
144
        // return Result
145
        return $result;
146
    }
147
148
    /**
149
     * This will retrieve all transactions within a given block height range.
150
     *
151
     * @url https://docs.factom.com/api#transactions-retrieving
152
     *
153
     * @return json { array transactions }
154
     */
155
    public function transactionsByRange(int $start, int $end)
0 ignored issues
show
Unused Code introduced by
The parameter $start is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $end is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
156
    {
157
        $result = $this->callEndpoint('transactions', 'POST');
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('transactions', 'POST'); of type object|string adds the type string to the return on line 160 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...pi::transactionsByRange of type AdrianMejias\FactomApi\json.
Loading history...
158
159
        // return Result
160
        return $result;
161
    }
162
163
    /**
164
     * This will retrieve a transaction by the given TxID.
165
     *
166
     * @url https://docs.factom.com/api#by-txid
167
     *
168
     * @return json { array transactions }
169
     */
170
    public function transactionsByTxID(string $txid)
0 ignored issues
show
Unused Code introduced by
The parameter $txid is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
171
    {
172
        $result = $this->callEndpoint('transactions', 'POST');
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('transactions', 'POST'); of type object|string adds the type string to the return on line 175 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...Api::transactionsByTxID of type AdrianMejias\FactomApi\json.
Loading history...
173
174
        // return Result
175
        return $result;
176
    }
177
178
    /**
179
     * Retrieves all transactions that an address is apart of.
180
     *
181
     * @url https://docs.factom.com/api#by-address
182
     *
183
     * @return json { array transactions }
184
     */
185
    public function transactionsByAddress(string $address)
186
    {
187
        $result = $this->callEndpoint('transactions', 'POST', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('tra...address' => $address)); of type object|string adds the type string to the return on line 192 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...::transactionsByAddress of type AdrianMejias\FactomApi\json.
Loading history...
188
            'address' => $address,
189
        ]);
190
191
        // return Result
192
        return $result;
193
    }
194
195
    /**
196
     * The developers were so preoccupied with whether or not they could,
197
     * they didn’t stop to think if they should.
198
     *
199
     * @url https://docs.factom.com/api#all-transactions
200
     * 
201
     * @warning The amount of data returned by this is so large.
202
     *
203
     * @return json { array transactions }
204
     */
205
    public function transactions(string $address)
0 ignored issues
show
Unused Code introduced by
The parameter $address is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
206
    {
207
        $result = $this->callEndpoint('transactions', 'POST');
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('transactions', 'POST'); of type object|string adds the type string to the return on line 210 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...WalletApi::transactions of type AdrianMejias\FactomApi\json.
Loading history...
208
209
        // return Result
210
        return $result;
211
    }
212
213
    /**
214
     * Lists all the current working transactions in the wallet.
215
     *
216
     * @url https://docs.factom.com/api#tmp-transactions
217
     *
218
     * @return json { array transactions }
219
     */
220
    public function tmpTransactions(string $address)
0 ignored issues
show
Unused Code introduced by
The parameter $address is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
221
    {
222
        $result = $this->callEndpoint('tmp-transactions', 'POST');
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('tmp-transactions', 'POST'); of type object|string adds the type string to the return on line 225 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...letApi::tmpTransactions of type AdrianMejias\FactomApi\json.
Loading history...
223
224
        // return Result
225
        return $result;
226
    }
227
228
    /**
229
     * Deletes a working transaction in the wallet.
230
     *
231
     * @url https://docs.factom.com/api#delete-transaction
232
     *
233
     * @return json { object ... }
234
     */
235
    public function deleteTransaction(string $txname)
236
    {
237
        $result = $this->callEndpoint('delete-transaction', 'GET', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('del...'tx-name' => $txname)); of type object|string adds the type string to the return on line 242 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...tApi::deleteTransaction of type AdrianMejias\FactomApi\json.
Loading history...
238
            'tx-name' => $txname,
239
        ]);
240
241
        // return Result
242
        return $result;
243
    }
244
245
    /**
246
     * This will create a new transaction.
247
     *
248
     * @url https://docs.factom.com/api#new-transaction
249
     *
250
     * @return json { object ... }
251
     */
252
    public function newTransaction(string $txname)
253
    {
254
        $result = $this->callEndpoint('new-transaction', 'GET', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('new...'tx-name' => $txname)); of type object|string adds the type string to the return on line 259 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...lletApi::newTransaction of type AdrianMejias\FactomApi\json.
Loading history...
255
            'tx-name' => $txname,
256
        ]);
257
258
        // return Result
259
        return $result;
260
    }
261
262
    /**
263
     * Adds an input to the transaction from the given address.
264
     *
265
     * @url https://docs.factom.com/api#add-input
266
     *
267
     * @return json { object ... }
268
     */
269 View Code Duplication
    public function addInput(string $txname, string $address, int $amount)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
270
    {
271
        $result = $this->callEndpoint('add-input', 'POST', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('add... 'amount' => $amount)); of type object|string adds the type string to the return on line 278 which is incompatible with the return type documented by AdrianMejias\FactomApi\FactomWalletApi::addInput of type AdrianMejias\FactomApi\json.
Loading history...
272
            'tx-name' => $txname,
273
            'address' => $address,
274
            'amount' => $amount,
275
        ]);
276
277
        // return Result
278
        return $result;
279
    }
280
281
    /**
282
     * Adds a factoid address output to the transaction.
283
     *
284
     * @url https://docs.factom.com/api#add-output
285
     *
286
     * @return json { object ... }
287
     */
288 View Code Duplication
    public function addOutput(string $txname, string $address, int $amount)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
289
    {
290
        $result = $this->callEndpoint('add-output', 'POST', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('add... 'amount' => $amount)); of type object|string adds the type string to the return on line 297 which is incompatible with the return type documented by AdrianMejias\FactomApi\FactomWalletApi::addOutput of type AdrianMejias\FactomApi\json.
Loading history...
291
            'tx-name' => $txname,
292
            'address' => $address,
293
            'amount' => $amount,
294
        ]);
295
296
        // return Result
297
        return $result;
298
    }
299
300
    /**
301
     * When adding entry credit outputs, the amount given is in factoshis, not entry credtis.
302
     *
303
     * @url https://docs.factom.com/api#add-ec-output
304
     *
305
     * @return json { object ... }
306
     */
307 View Code Duplication
    public function addEcOutput(string $txname, string $address, int $amount)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
308
    {
309
        $result = $this->callEndpoint('add-ec-output', 'POST', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('add... 'amount' => $amount)); of type object|string adds the type string to the return on line 316 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...mWalletApi::addEcOutput of type AdrianMejias\FactomApi\json.
Loading history...
310
            'tx-name' => $txname,
311
            'address' => $address,
312
            'amount' => $amount,
313
        ]);
314
315
        // return Result
316
        return $result;
317
    }
318
319
    /**
320
     * Addfee is a shortcut and safeguard for adding the required additonal factoshis to covert the fee.
321
     *
322
     * @url https://docs.factom.com/api#add-fee
323
     *
324
     * @return json { object ... }
325
     */
326
    public function addFee(string $txname, string $address)
327
    {
328
        $result = $this->callEndpoint('add-fee', 'POST', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('add...address' => $address)); of type object|string adds the type string to the return on line 334 which is incompatible with the return type documented by AdrianMejias\FactomApi\FactomWalletApi::addFee of type AdrianMejias\FactomApi\json.
Loading history...
329
            'tx-name' => $txname,
330
            'address' => $address,
331
        ]);
332
333
        // return Result
334
        return $result;
335
    }
336
337
    /**
338
     * When paying from a transaction, you can also make the recieving transaction pay for it.
339
     *
340
     * @url https://docs.factom.com/api#sub-fee
341
     *
342
     * @return json { object ... }
343
     */
344
    public function subFee(string $txname, string $address)
345
    {
346
        $result = $this->callEndpoint('sub-fee', 'POST', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('sub...address' => $address)); of type object|string adds the type string to the return on line 352 which is incompatible with the return type documented by AdrianMejias\FactomApi\FactomWalletApi::subFee of type AdrianMejias\FactomApi\json.
Loading history...
347
            'tx-name' => $txname,
348
            'address' => $address,
349
        ]);
350
351
        // return Result
352
        return $result;
353
    }
354
355
    /**
356
     * Signs the transaction. It is now ready to be signed.
357
     *
358
     * @url https://docs.factom.com/api#sign-transaction
359
     *
360
     * @return json { object ... }
361
     */
362
    public function signTransaction(string $txname)
363
    {
364
        $result = $this->callEndpoint('sign-transaction', 'POST', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('sig...'tx-name' => $txname)); of type object|string adds the type string to the return on line 369 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...letApi::signTransaction of type AdrianMejias\FactomApi\json.
Loading history...
365
            'tx-name' => $txname,
366
        ]);
367
368
        // return Result
369
        return $result;
370
    }
371
372
    /**
373
     * Signs the transaction. It is now ready to be signed.
374
     *
375
     * @url https://docs.factom.com/api#compose-transaction
376
     *
377
     * @return json { object ... }
378
     */
379
    public function composeTransaction(string $txname)
380
    {
381
        $result = $this->callEndpoint('compose-transaction', 'POST', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('com...'tx-name' => $txname)); of type object|string adds the type string to the return on line 386 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...Api::composeTransaction of type AdrianMejias\FactomApi\json.
Loading history...
382
            'tx-name' => $txname,
383
        ]);
384
385
        // return Result
386
        return $result;
387
    }
388
389
    /**
390
     * This method, compose-chain, will return the appropriate api calls to create a chain in factom.
391
     *
392
     * @url https://docs.factom.com/api#compose-chain
393
     *
394
     * @return json { object ... }
395
     */
396
    public function composeChain(array $extids, string $content, string $ecpub)
397
    {
398
        $result = $this->callEndpoint('compose-chain', 'POST', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('com...), 'ecpub' => $ecpub)); of type object|string adds the type string to the return on line 409 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...WalletApi::composeChain of type AdrianMejias\FactomApi\json.
Loading history...
399
            'chain' => [
400
                'firstentry' => [
401
                    'extids' => $extids,
402
                    'content' => $content,
403
                ],
404
            ],
405
            'ecpub' => $ecpub,
406
        ]);
407
408
        // return Result
409
        return $result;
410
    }
411
412
    /**
413
     * This method, compose-entry, will return the appropriate api calls to create a entry in factom.
414
     *
415
     * @url https://docs.factom.com/api#compose-entry
416
     *
417
     * @return json { object ... }
418
     */
419
    public function composeEntry(string $chainid, array $extids, string $content, string $ecpub)
420
    {
421
        $result = $this->callEndpoint('compose-entry', 'POST', [
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('com...), 'ecpub' => $ecpub)); of type object|string adds the type string to the return on line 431 which is incompatible with the return type documented by AdrianMejias\FactomApi\F...WalletApi::composeEntry of type AdrianMejias\FactomApi\json.
Loading history...
422
            'entry' => [
423
                'chainid' => $chainid,
424
                'extids' => $extids,
425
                'content' => $content,
426
            ],
427
            'ecpub' => $ecpub,
428
        ]);
429
430
        // return Result
431
        return $result;
432
    }
433
434
    /**
435
     * Retrieve current properties of factom-walletd, including the wallet and wallet API versions.
436
     *
437
     * @url https://docs.factom.com/api#properties
438
     *
439
     * @return json { string walletversion, string walletapiversion }
440
     */
441
    public function properties()
442
    {
443
        $result = $this->callEndpoint('properties', 'POST');
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callEndpoint('properties', 'POST'); of type object|string adds the type string to the return on line 446 which is incompatible with the return type documented by AdrianMejias\FactomApi\FactomWalletApi::properties of type AdrianMejias\FactomApi\json.
Loading history...
444
445
        // return Result
446
        return $result;
447
    }
448
}
449