Esempio n. 1
0
 /// Call the wallet API to create a coinbase output for the given block_fees.
 /// Will retry based on default "retry forever with backoff" behavior.
 public static CbData create_coinbase(string url, BlockFees blockFees)
 {
     return(retry_backoff_forever(
                () =>
     {
         try
         {
             var res = single_create_coinbase(url, blockFees);
             return res;
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
             throw;
         }
     }));
 }
        public CbData build_coinbase(BlockFees bf)
        {
            var(outp, kern, blockFees) = WalletReceiver.WalletReceiver.receive_coinbase(
                Config,
                Keychain,
                bf);

            //                             ).map_err(|e| {
            //    api::Error::Internal(format!("Error building coinbase: {:?}", e))

            //})?;

            //var out_bin = ser::ser_vec(&out).map_err(| e | {

            //     api::Error::Internal(format!("Error serializing output: {:?}", e))

            // })?;
            var outBin = Ser.Ser_vec(outp);

            // let kern_bin = ser::ser_vec(&kern).map_err(| e | {

            //     api::Error::Internal(format!("Error serializing kernel: {:?}", e))

            // })?;

            var kernBin = Ser.Ser_vec(kern);

            //    let key_id_bin = match block_fees.key_id_set {

            //        Some(key_id_set) => {
            //            ser::ser_vec(&key_id_set).map_err(|e| {
            //                api::Error::Internal(
            //                    format!("Error serializing kernel: {:?}", e),

            //                    )

            //            })?
            //        }
            //        None => vec![],
            //    };


            var keyIdBin = blockFees.KeyId != null ? blockFees.KeyId.Value : new byte[Identifier.IdentifierSize];

            return(new CbData(HexUtil.to_hex(outBin), HexUtil.to_hex(kernBin), HexUtil.to_hex(keyIdBin)));
        }
Esempio n. 3
0
        /// Makes a single request to the wallet API to create a new coinbase output.
        public static CbData single_create_coinbase(string url, BlockFees blockFees)
        {
            var json          = JsonConvert.SerializeObject(blockFees);
            var stringContent = new StringContent(
                json,
                Encoding.UTF8,
                "application/json");

            var req = ApiClient.PostContentAsync(url, stringContent).Result;

            if (req.IsSuccessStatusCode)
            {
                var stream = req.Content.ReadAsStreamAsync().Result;
                var cbData = stream.ReadJson <CbData>();
                return(cbData);
            }

            throw new Exception(req.StatusCode.ToString());
        }
        public IActionResult Handle(BlockFees cb)
        {
            var coinbase = build_coinbase(cb);

            return(new JsonResult(coinbase));
        }