Exemplo n.º 1
0
        /// Receive an already well formed JSON transaction issuance and finalize the
        /// transaction, adding our receiving output, to broadcast to the rest of the
        /// network.
        public static void receive_json_tx(
            WalletConfig config,
            Keychain keychain,
            PartialTx partialTx
            )
        {
            var(amount, blinding, tx) = PartialTx.read_partial_tx(keychain, partialTx);

            var finalTx = receive_transaction(config, keychain, amount, blinding, tx);

            var txHex = HexUtil.to_hex(Ser.Ser_vec(finalTx));

            //todo:asyncification

            var url = $"{config.CheckNodeApiHttpAddr}/v1/pool/push";

            var json = JsonConvert.SerializeObject(new TxWrapper {
                TxHex = txHex
            });

            var res = ApiClient.PostContentAsync(url, new StringContent(json, Encoding.UTF8, "application/json")).Result;

            if (!res.IsSuccessStatusCode)

            {
                Log.Debug("{statusCode}", res.StatusCode);
                throw new WalletErrorException(WalletError.Node, $"{res.StatusCode}");
            }



            // var res = ApiClient.PostAsync(uri, new JsonContent(new TxWrapper(){tx_hex=tx_hex})).Result;

            //let url = format!("{}/v1/pool/push", config.check_node_api_http_addr.as_str());
            //let _: () = api::client::post(url.as_str(), &TxWrapper { tx_hex: tx_hex
            //})
            //.map_err(|e| Error::Node(e))?;
        }