Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 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() |
||
| 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) |
||
| 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) |
||
| 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() |
||
| 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() |
||
| 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() |
||
| 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) |
||
| 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) |
||
| 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() |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
|
| 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) |
|
| 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) |
|
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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() |
||
| 448 | } |
||
| 449 |