Exemplo n.º 1
0
        public static void issue_burn_tx(
            WalletConfig config,
            Keychain keychain,
            ulong amount,
            ulong minimumConfirmations,
            uint maxOutputs
            )
        {
            keychain = Keychain.Burn_enabled(keychain, Identifier.Zero());

            var chainTip      = Checker.get_tip_from_node(config);
            var currentHeight = chainTip.Height;

            var _ = Checker.refresh_outputs(config, keychain);

            var keyId = keychain.Root_key_id();

// select some spendable coins from the walvar
            var coins = WalletData.Read_wallet(
                config.DataFileDir, walletData => walletData.Select(
                    keyId.Clone(),
                    amount,
                    currentHeight,
                    minimumConfirmations,
                    maxOutputs,
                    false));


            Log.Debug("selected some coins - {}", coins.Length);

            var(partsArray, _) = inputs_and_change(coins, config, keychain, amount);

            var parts = partsArray.ToList();

            // add burn output and fees
            var fee = Types.tx_fee((uint)coins.Length, 2, null);

            parts.Add(c => c.Output(amount - fee, Identifier.Zero()));

            // finalize the burn transaction and send
            var(txBurn, _) = Build.Transaction(parts.ToArray(), keychain);
            txBurn.Validate(keychain.Secp);

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

            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;

            Log.Debug("{StatusCode}", res.StatusCode);
        }