Closed bazooka70 closed 6 years ago
@NicolasDorier Verify() should probably return void (instead of bool), and throw exceptions for each verification failure.
@bazooka70 there is probably a good reason which would make it not work on mainnet.
Policy.TransactionPolicyError[] errors = = null;
builder.Verify(tx, out errors);
check errors
then.
@NicolasDorier , Thanks. I got an error: "Fee too low, actual is 0.00001008, policy minimum is 0.00001120". I changed the Fee to 0.00001120 and now it returned True.
I actually used 0.00001008 from Bitcoin Core "estimatesmartfee(6)" when I was testing. so why is the builder complains and where does it gets that Fee number from? Also, Can we eliminate this internal check?
Better not, it just catched a bug from you... You should use SendEstimatedFee
not SendFee
, estimatesmartfee sends back a FeeRate (BTC/KB), not a fee.
@NicolasDorier , I think I'm lost... :(
FeeRate feeRate = new FeeRate(new Money(0.00001264m, MoneyUnit.BTC));
var builder = new TransactionBuilder();
var tx = builder
.AddCoins(coinsToSpend)
.AddKeys(signingKeys.ToArray())
.Send(addressToSend, amountToSend)
.SetChange(changeScriptPubKey)
.SendEstimatedFees(feeRate)
.BuildTransaction(true);
Verify
Returns error
Fee too low, actual is 0.00000283, policy minimum is 0.00001120
FeeRate feeRate = new FeeRate(new Money(0.00001264m, MoneyUnit.BTC), 1000);
Bitcoin core is sending BTC per KB.
does 0.00001264m
come direclty from bitcoin core ?
Ok so I checked, it turned out that bitcoin core dropped down the minTxRelayFee
from 5000 satoshi to 1000 satoshi per KB for the network, thus your fee estimation was below what NBitcoin consider safe.
You code is fine, try version 4.0.0.56
which should fix your issue.
There is a way to disable this check TransactionBuilder.Policy.MinRelayTx
(or something like that), but please do not remove it, it might catch bug in your code.
@NicolasDorier , Thanks.
estimatesmartfee(6)
returns 0.00004990 on MainNet;
estimatesmartfee(6)
returns 0.00001016 on TestNet
So the formula I need to use is (Pseudo):
FeeRate feeRate = new FeeRate(new Money(estimatesmartfee(6), MoneyUnit.BTC), 1000);
?
Does the 1000 (size) represent the KB?
Yes, @bazooka70 just update the package your code as before should work. By default the second parameter is 1000 so I don't think it will change anything.
Policy.TransactionPolicyError[] errors =null;
builder.Verify(tx, out errors);
if (errors != null)
{
foreach (var e in errors)
{
Console.WriteLine("builder error-> " + e.ToString());
}
}
@NicolasDorier I think it is important to add something like e.ErrorCode
(enumerator maybe?) for each error in the errors array so we can know what the error refers to, and return our own error message based on the ErrorCode
.
What do you think? Please don't ask me to make a PR... :-P
Well you can already do that, all errors are strongly typed so you can use the type of the error to print the right message.
I'm not sure what you mean by strongly typed since all errors in the collection are of type TransactionPolicyError
.
This is only the base type. Look in NBitcoin.Policy for all different type of errors.
Got it! thanks.
What could cause TransactionBuilder.Verify to return false? This transaction is successfully signed, and I'm able to broadcast it to the blockchain, but for some reason it always returns "false". e.g.
The result transaction looks like:
The amounts and fee seems OK, and the fact that the transaction is accepted on the blockchain just drives me crazy. Please assist. I am currently using a single Testnet address for my transactions (including the change address)
Here are all the successful transactions I made:
https://live.blockcypher.com/btc-testnet/address/mkE9yyrgdttSRY7UYQLVUHVY9g7Saqh2Qv/