コード例 #1
0
 public function testCreateRaw()
 {
     /*$arr = [
           "010000000869c2997e9dd8ce50f9481a33971f0308e8d525ef8bf079f455fc7936d13f375a1f0000008a47304402202de0d834112506ed10549f751ce142094243390f3e035444f105b4764056314302205dfddc421b377c8b089182ddb3928ce02e73c86e5dfb9e66ca6a98810d7a2ac5014104b3d8c8c5896b0ed9537ccbdcfdf3f05cd4299988c72d078b841e0491bab198702c4befaa3da367c117c7c6217cd478c54b572e13de6ddd22c948f4b66c1562b5ffffffffab9aae4a00230f30795cd928225e9f69f7c0e6146c535b641541cb81aa09b5297b0000008a47304402205604456b1ed6dcae5e5f370568dd71c8bfb44823d583e3fa781ae8117ed831a30220154ee1c49bfca8bd1970953255498cb6bc347de1df267ed1b0f70385bca29184014104b3d8c8c5896b0ed9537ccbdcfdf3f05cd4299988c72d078b841e0491bab198702c4befaa3da367c117c7c6217cd478c54b572e13de6ddd22c948f4b66c1562b5ffffffffc036184c5aa93f74530359251e6ff63ab9e17ce7eb6f5d467c42675e318696e5010000008a47304402206c756a38757443794196d16e887c95b9b769b11c608b425e7580e4fcd8456642022040613fbff5e5412c8aa0c3a91b651a6fe6fcf793596a5e29bbc7bc5d73fc683a014104b3d8c8c5896b0ed9537ccbdcfdf3f05cd4299988c72d078b841e0491bab198702c4befaa3da367c117c7c6217cd478c54b572e13de6ddd22c948f4b66c1562b5ffffffff727107bfb37c254f12b4dfdda9ded7544ea6e44298a657ecb1863e00f88e0700110000008c493046022100c24b9c50820d19457fc5842a124500bf2371397144fc6166bdaa4a94275e9dda022100fc6c59286cfdc2fca4cca62d0a1b4e7dd8125a18aee59e630877f85101aa441a014104b3d8c8c5896b0ed9537ccbdcfdf3f05cd4299988c72d078b841e0491bab198702c4befaa3da367c117c7c6217cd478c54b572e13de6ddd22c948f4b66c1562b5fffffffffb862000126a61dba547524f7302bc68ea177cf00f7a49c5b834c0fd397c4dfe390000008b483045022100c837ec9105ddaa75250a38e9942a624754ecacb025feb024adfa8a77914e6eff0220538a1407d7ed8b7417421113ee29c3d9699f87780907b4121068740f1eb31d68014104b3d8c8c5896b0ed9537ccbdcfdf3f05cd4299988c72d078b841e0491bab198702c4befaa3da367c117c7c6217cd478c54b572e13de6ddd22c948f4b66c1562b5ffffffffdb35b57c65cf0fcdea54bfdebda43942d728001a06a9df0404a07801c87ccd8a090000008b483045022100b00faaa1b6a7c1cbe4c47791e302bbcbf1d4fee54cb3d1195d82ef05df0f8f0702207382b68bb44e8fadb0ae7b44f22a18df93e8e8e000d28c88f4fdff78d92a8316014104b3d8c8c5896b0ed9537ccbdcfdf3f05cd4299988c72d078b841e0491bab198702c4befaa3da367c117c7c6217cd478c54b572e13de6ddd22c948f4b66c1562b5ffffffff539ff8e14dab98db92dbbaff03dda50136470bb30bf9fb5b844eb356bc31362d1f0000008b48304502205e41d2112c190396173562d7957b16e0bba64a40adbe466cfe98778d30d91fa20221009f62ac2e345dbd16639b4269c86f156c050e5747013d2a452cdd8c25b8c9aeb9014104b3d8c8c5896b0ed9537ccbdcfdf3f05cd4299988c72d078b841e0491bab198702c4befaa3da367c117c7c6217cd478c54b572e13de6ddd22c948f4b66c1562b5ffffffffbc0dabbf27d0a58f0e2f5a36c11e7f270737ddc92ef0d8d1baacdeff24f39ed7110000008a473044021f3cfe420bd8a5baca342a3df2501f03165e8b8b76fea6fbc82dd05047c99fcd022100bfa829bce78d4f463abefbba943ea54dbbd931b5d7712e263eaf76d2779cf053014104b3d8c8c5896b0ed9537ccbdcfdf3f05cd4299988c72d078b841e0491bab198702c4befaa3da367c117c7c6217cd478c54b572e13de6ddd22c948f4b66c1562b5ffffffff023011e100000000001976a91431b07b8df3c19573388bb688b4fd89f6233f5d7988acf4f31400000000001976a914d17e062579b71bfe199a80991a253d929f8bd35b88ac00000000",
           "01000000074829be5251cac2c2f6bc5bb71b37a7cd57504408d42010b4a924dc4dd60dabba000000006b483045022100921b883c6a42e14a3718fa2b0b9cc72225c761121710fd380e8ffc25766b3f8302200c436640eeeb6dded3950d9782bb101ca6ebd6f3a7371a4f94f4d769d0e09292012103417cff182cd9886e693868f474d26af984e9af82b3d83116eb5bb591bbb87e0effffffff7841ac6b34686946bff2996ee7a8c347efc4906f565ca15dec507faa085ed8a9000000006a47304402207499620cb0e7db680df261b10beca91988746389b51664f0906f30a8e96a7db60220410ca07f12a3edfb1521bd5c9b18c83f6ccc2ced62ff1fb910b4d2a4ad73ef16012103417cff182cd9886e693868f474d26af984e9af82b3d83116eb5bb591bbb87e0effffffff7806bbe4b6e2b43c677f86845cee3e43d43e4e6da2f387cd15b3fcbafde436fb000000006a47304402201200e9c0a2a452f59ce94fff83128b1795cb2d241a79cd49ea90e56972e70d320220403640d7d103366a2b2f1e0782c3bbb5166c7947b500303b448e8fde27c02987012103417cff182cd9886e693868f474d26af984e9af82b3d83116eb5bb591bbb87e0effffffff129ef9ae1bf2382bd123005102723eaeab4cd9a2287286c1286db74a836c68d6000000006a47304402206392c220d6cd142e9423d559791cc318f3be87d91049d6ee76fdeddec69ceb0d02201240b24be64041ef6a3b0ae94935b23d357a8dbcb1e379ee7d2a58e33b66e72a012103417cff182cd9886e693868f474d26af984e9af82b3d83116eb5bb591bbb87e0effffffff2d918344bedaabd0a8406368518e2ba0ac0f48edd5733ef17909dfab6146789d000000006b483045022100bbdd6943c2233340de453f44f17641846df5d0e319782af48965eee9a2f40de80220304f7b200086b519b4f9b583c598e949f63df96539706391b813f0262a94beb4012103417cff182cd9886e693868f474d26af984e9af82b3d83116eb5bb591bbb87e0efffffffffa83a3af885f23269b4fe583d38510a9902924399816ede03a95160c3cb87b3f000000006a4730440220397bfa4185f41910f80d18bc9ef29cb9583299b668175cf1fd01c0f62176ffc302206d11ba8807a7de0033553a44ef5535f100e62158f04e2cff7140506afef761de012103417cff182cd9886e693868f474d26af984e9af82b3d83116eb5bb591bbb87e0effffffff3a0645bd4adcd0094d1e3c06104dd5037f53f14b7f533dacf5c3c02ffdd41a90000000006b4830450221009accebcf34cda23a9ded8dacaa6f80c87eaa734c2bc80b8aeaab4fe9b7ef9a1502202ce314930e89cee1a527daed448a52fe11bb77867aa5a8e33b07e24a2246ae96012103417cff182cd9886e693868f474d26af984e9af82b3d83116eb5bb591bbb87e0effffffff02676df004000000001976a9141713a60c250ad7e1b909baf09c3291257eef381188acbbde2500000000001976a914e3cf40e4218cdf11d9f3f339035a4b0937ba0a5888ac00000000",
           "01000000049c90b31e3ea1b3f157b64c6c12832292b3da372c23458fab097f660728f8d72b010000006a473044022008cc581b5a99c35683beb551770ffbebad6605f84a35118c25cc1d7685b5aeb402207b158c110b72cd635213eed7305ca762922ec464583c2d5dfb0f4e43562250b10121022235905741eb82e063b9736a3ced9e3686c0ca4fb14c9bb6e0c8cbdf308cf41dffffffffdb16fbc52a0b77fa466f4501b7dc8af2d9218e32d852f0a6a77e3d0063acb8f9000000006a47304402206c441ed1020c8a36ad6edd1f0c7296ee3d2f390cfca8893973c0714073a9c9cc022023ac27df5e8017c1933847dcbcb471e1349941a81bc83e98b358eea54f01d20a012103829a75e07a0c490f413455798cc7f4a6330f9a403491e063b44862f542b622caffffffff9e65c29ac0ae80db55c72915ecef387f2d2c4ad066694e6b6e3ea5868cb788b6010000006b483045022100a7544728bf36ad8e80927caae7fe6d8d74129f03ba37a841edf8984cc467fd2602203e2603ecf5fdd56e4ed5cde8034ee731535e980e4b84e2759471f7df76cda164012103d8959922eba9a927dec4d742f940e9421c705ae661c15b1a47e3e0baafbc0547ffffffffacffa835a861226cfc63f9b491fc1d5f782b0a9d82f9ee62c99a65eac8ff90a5000000006b483045022100b3aadc533e6de0fe5d9b14861526feddc988cf9e7d7c80eee9ccbd8b2883276502206bf589498a08b44e82b6e5f398d95820ad1e766844189dea202b8b390954176b0121037d14b11915f8f58ba90e6f219abbdb4bc48fdf412094dda6d5790f0edf084cf2ffffffff0aab3ccc10000000001976a9149a305f166390604123d628af06c8897324ae1b6688ac20965904000000001976a9140c0850e3da96e15fc722545f28bced12b46ff5bb88ac66409005000000001976a9149191be4fd37c3391e918a641626cfaf39594923a88ac107c5a00000000001976a914b46a76ad1f35e26f41251a79f68e65fb873d361688acc1b90f00000000001976a9143d0119812e60b1d71e42867dbc6ec09507d618d188ace0e76d01000000001976a914bdd386cd9deeace2557eabc489dcf2a699b82cb388ac7f420f00000000001976a9147c554abe9bf802a53b0cfd70c95c3860fdfefd3588ac4b765509000000001976a914f33c0d7be35d6d146d4618f665d4118b622d200d88acc4d55d0a000000001976a914396da404b5d95fa2261928de51157cc1052ccce188acec314100000000001976a914f09c529f3ebd2097ab81fc50145ba104058c938f88ac00000000",
           "0100000004bf3ff395d579649914060b71487e466e6fd09604eb62f57ffb63ce702b0c60ab000000008c493046022100896c3dcdaf7c01cf86d9a8105bc54b9065bc26a8a9ea478a491d244b466bf64c0221009377176af0277c45b9c81433d9983d34bb1cdbc37a7479d4a8bbdde4a5d192a0014104a5ed97469860bbe8f05b9964dbc83bb17e5d14383a54fc4395e1e698d01011f6827632c50871df697d46faab766a267cd3b12a17244db5af311133953b440e31ffffffff7010eb5de98223f6048c4e048b4c47b9078b5e6ea679f7d5a4e78d88def33002000000008b48304502206773a142ab11bd4bcac34f55f64ffd488dbdc8dc2a9197d75b1f3bf1da5c00ff022100c4c65d5ea66b00162a3744a9ff3ae60aeb19507e9c30a5ea9ea27fc26306007b014104a5ed97469860bbe8f05b9964dbc83bb17e5d14383a54fc4395e1e698d01011f6827632c50871df697d46faab766a267cd3b12a17244db5af311133953b440e31ffffffff705d8a483f532355a9a3cc4c2f8e9604ec5da99df9689319f0eb75378fd2b5a5000000008b48304502202e5299ab19138468421b4c48c5a78d7ed9e4783a266dd827b915dc27051755a002210093b4377bf0a0bf1ff0a40a996255463bc706ca49a7b23f45999125774c0b7d75014104a5ed97469860bbe8f05b9964dbc83bb17e5d14383a54fc4395e1e698d01011f6827632c50871df697d46faab766a267cd3b12a17244db5af311133953b440e31ffffffff8a0dfdaa0b30c5af535a1791ce3f0f158e197f311d6696b20b6ff56f89f27602000000008b4830450220472537228e29b49a06a9255b86323c2cf5a230fce789ef3b0a308aa58f9dafd4022100a14cfbafbbc682759d5491a2c4dfa1f8287649fafa88c0166fb7b9ef9e77d999014104a5ed97469860bbe8f05b9964dbc83bb17e5d14383a54fc4395e1e698d01011f6827632c50871df697d46faab766a267cd3b12a17244db5af311133953b440e31ffffffff0234b13c00000000001976a914794e3a3f5f542ebb3f2e640ea9417e3c7d41e40b88acfc4d2a00000000001976a914b526df90f2bb0c5830b469b8b8f96d25e127de5d88ac00000000",
           "01000000011aaebeeb686e02c3471f0cf9f12eb6d69e45c3dd89cc0fa135e26ca72ec8d2c1020000006b483045022100f119173e52f8950dc0f369c64546746b900d621633f7a1d9b386232b5c21d6430220197f389584d087f34d250ffc8e5908a6ec9651fd02f64f200d3a60abe0df4287012102a1c5150347aa359ad363b7ccaf8602e7538de37935ebb2bb1656e20bfc6cd111ffffffff02b421e428000000001976a91443d6d50fb700dc1d98494942f8c378b8cbbb0def88ac80969800000000001976a9148e10169967933a59a77260277bb6f4d2869ed53088ac00000000"
       ];*/
     $data = [1 => ['inputs' => [["txid" => "5a373fd13679fc55f479f08bef25d5e808031f97331a48f950ced89d7e99c269", "vout" => 31, "scriptPubKey" => "76a914d17e062579b71bfe199a80991a253d929f8bd35b88ac"], ["txid" => "29b509aa81cb4115645b536c14e6c0f7699f5e2228d95c79300f23004aae9aab", "vout" => 123, "scriptPubKey" => "76a914d17e062579b71bfe199a80991a253d929f8bd35b88ac"], ["txid" => "e59686315e67427c465d6febe77ce1b93af66f1e25590353743fa95a4c1836c0", "vout" => 1, "scriptPubKey" => "76a914d17e062579b71bfe199a80991a253d929f8bd35b88ac"], ["txid" => "00078ef8003e86b1ec57a69842e4a64e54d7dea9dddfb4124f257cb3bf077172", "vout" => 17, "scriptPubKey" => "76a914d17e062579b71bfe199a80991a253d929f8bd35b88ac"], ["txid" => "fe4d7c39fdc034b8c5497a0ff07c17ea68bc02734f5247a5db616a12002086fb", "vout" => 57, "scriptPubKey" => "76a914d17e062579b71bfe199a80991a253d929f8bd35b88ac"], ["txid" => "8acd7cc80178a00404dfa9061a0028d74239a4bddebf54eacd0fcf657cb535db", "vout" => 9, "scriptPubKey" => "76a914d17e062579b71bfe199a80991a253d929f8bd35b88ac"], ["txid" => "2d3631bc56b34e845bfbf90bb30b473601a5dd03ffbadb92db98ab4de1f89f53", "vout" => 31, "scriptPubKey" => "76a914d17e062579b71bfe199a80991a253d929f8bd35b88ac"], ["txid" => "d79ef324ffdeacbad1d8f02ec9dd3707277f1ec1365a2f0e8fa5d027bfab0dbc", "vout" => 17, "scriptPubKey" => "76a914d17e062579b71bfe199a80991a253d929f8bd35b88ac"]], 'outputs' => ["15XjXdS1qTBy3i8vCCriWSAbm1qx5JgJVz" => 0.1475, "1L6hCPsCq7C5rNzq7wSyu4eaQCq8LeipmG" => 0.01373172]]];
     foreach ($data as $test) {
         $create = RawTransaction::create($test['inputs'], $test['outputs'], '00');
         $this->assertTrue(is_string($create));
     }
 }
コード例 #2
0
 /**
  * create a signed transaction sending all the found outputs to the given address
  *
  * @param $destinationAddress
  * @return array
  * @throws \Exception
  */
 protected function createTransaction($destinationAddress)
 {
     if ($this->debug) {
         echo "\nCreating transaction to address {$destinationAddress}";
     }
     // create raw transaction
     $inputs = [];
     foreach ($this->sweepData['utxos'] as $address => $data) {
         $inputs = array_merge($inputs, array_map(function ($utxo) use($address, $data) {
             return ['txid' => $utxo['hash'], 'vout' => $utxo['index'], 'scriptPubKey' => $utxo['script_hex'], 'value' => $utxo['value'], 'address' => $address, 'path' => $data['path'], 'redeemScript' => $data['redeem']];
         }, $data['utxos']));
     }
     $outputs = [];
     $fee = Wallet::estimateFee($this->sweepData['count'], 1);
     $outputs[$destinationAddress] = $this->sweepData['balance'] - $fee;
     //create the raw transaction
     $rawTransaction = RawTransaction::create($inputs, $outputs);
     if (!$rawTransaction) {
         throw new \Exception("Failed to create raw transaction");
     }
     if ($this->debug) {
         echo "\nSigning transaction";
     }
     //sign the raw transaction
     $transaction = $this->signTransaction($rawTransaction, $inputs);
     if (!$transaction['sign_count']) {
         throw new \Exception("Failed to sign transaction");
     }
     return $transaction;
 }
コード例 #3
0
$inputs = array(array('txid' => '6737e1355be0566c583eecd48bf8a5e1fcdf2d9f51cc7be82d4393ac9555611c', 'vout' => 0, 'value' => 0.0002, 'scriptPubKey' => '76a9147e3f939e8ded8c0d93695310d6d481ae5da3961688ac'));
// sum up the total amount of coins we're spending
$inputsTotal = 0;
foreach ($inputs as $input) {
    $inputsTotal += $input['value'];
}
// fixed fee
$fee = 0.0001;
// information of who we're sending coins to and how much
$to = '1PGa6cMAzzrBpTtfvQTzX5PmUxsDiFzKyW';
$send = 5.0E-5;
// calculate change
$change = $inputsTotal - $send - $fee;
// this is our own address
$changeAddress = "1CWYJZ4vSoemSCrfBvXreqEtojEeCUeKw3";
// create ouputs, one to recipient and one to change
$outputs = array($to => BitcoinLib::toSatoshi($send), $changeAddress => BitcoinLib::toSatoshi($change));
// import private key
$wallet = array();
RawTransaction::private_keys_to_wallet($wallet, array('L2V4QgXVUyWVoMGejTj7PrRUUCEi9D9Y1AhUM8E6f5yJm7gemgN6'), '00');
// crate unsigned raw transaction
$raw_transaction = RawTransaction::create($inputs, $outputs);
// sign the transaction
// to broadcast transaction take this value and `bitcoin-cli sendrawtransaction <hex>`
$sign = RawTransaction::sign($wallet, $raw_transaction, json_encode($inputs));
print_r($sign);
echo "\n";
// set the transaction hash from the raw transaction
$txid = RawTransaction::txid_from_raw($sign['hex']);
print_r($txid);
echo "\n";
コード例 #4
0
 private function createRawExpectException($inputs, $outputs, $message = "")
 {
     $e = null;
     try {
         RawTransaction::create($inputs, $outputs);
     } catch (\Exception $e) {
     }
     $this->assertTrue(!!$e, "should have thrown exception [{$message}]");
 }
コード例 #5
0
 /**
  * !! INTERNAL METHOD, public for testing purposes !!
  * create, sign and send transction based on inputs and outputs
  *
  * @param      $inputs
  * @param      $outputs
  * @param bool $apiCheckFee     let the API check if the fee is correct
  * @return string
  * @throws \Exception
  * @internal
  */
 public function _sendTx($inputs, $outputs, $apiCheckFee = true)
 {
     if ($this->locked) {
         throw new \Exception("Wallet needs to be unlocked to pay");
     }
     // create raw unsigned TX
     $raw_transaction = RawTransaction::create($inputs, $outputs);
     if (!$raw_transaction) {
         throw new \Exception("Failed to create raw transaction");
     }
     // sign the transaction with our keys
     $signed = $this->signTransaction($raw_transaction, $inputs);
     if (!$signed['sign_count']) {
         throw new \Exception("Failed to partially sign transaction");
     }
     // send the transaction
     $finished = $this->sendTransaction($signed['hex'], array_column($inputs, 'path'), $apiCheckFee);
     return $finished;
 }
コード例 #6
0
 /**
  * Create Spend Transaction
  *
  * This function takes a $from_address, an order address, and a $tx_outs array,
  * specifying who the transaction should pay.
  *
  * Returns TRUE if the transaction is successfully created, and previous details
  * removed, or else a string containing an error if it fails.
  *
  * @param string $from_address
  * @param array $tx_outs
  * @param string $script
  * @return bool|string
  */
 public function create_spend_transaction($from_address, array $tx_outs = array(), $script)
 {
     if (count($tx_outs) < 1) {
         return 'No outputs specified in transaction.';
     }
     $this->load->model('transaction_cache_model');
     // Add the inputs at the multisig address.
     $payments = $this->transaction_cache_model->payments_to_address($from_address);
     if (count($payments) == 0) {
         return 'No spendable outputs found for this address';
     }
     $order_id = $payments[0]['order_id'];
     // Create the transaction inputs
     $tx_ins = array();
     $tx_pkScripts = array();
     foreach ($payments as $pmt) {
         $tx_ins[] = array('txid' => $pmt['tx_id'], 'vout' => $pmt['vout']);
         $tx_pkScripts[] = array('txid' => $pmt['tx_id'], 'vout' => (int) $pmt['vout'], 'scriptPubKey' => $pmt['pkScript'], 'redeemScript' => $script);
     }
     $json = json_encode($tx_pkScripts);
     $tx_outs = array_map('strval', $tx_outs);
     $raw_transaction = RawTransaction::create($tx_ins, $tx_outs);
     if ($raw_transaction == FALSE) {
         return 'An error occurred creating the transaction!';
     } else {
         // Embed redeem script into all tx's
         $new_tx = RawTransaction::decode($raw_transaction);
         foreach ($new_tx['vin'] as &$input_ref) {
             //$empty_input = $script;
             $input_ref['scriptSig']['hex'] = $script;
         }
         $raw_transaction = RawTransaction::encode($new_tx);
         $decoded_transaction = RawTransaction::decode($raw_transaction);
         if ($this->update_order($order_id, array('unsigned_transaction' => $raw_transaction . " ", 'json_inputs' => "'{$json}'", 'partially_signed_transaction' => '', 'partially_signed_time' => '', 'partially_signing_user_id' => ''))) {
             $this->transaction_cache_model->clear_expected_for_address($from_address);
             $this->transaction_cache_model->log_transaction($decoded_transaction['vout'], $from_address, $order_id);
             return TRUE;
         }
         return 'An error occured updating the order!';
     }
 }