GithubHelp home page GithubHelp logo

mrtnetwork / bitcoin_base Goto Github PK

View Code? Open in Web Editor NEW
17.0 4.0 13.0 644 KB

A versatile library for Bitcoin, Dogecoin, Litecoin, Dash, BSV and Bitcoin Cash. Supports P2PK, P2PKH, P2SH, P2WPKH, P2WSH, Taproot, with advanced creation, signing, and spending capabilities.

License: BSD 3-Clause "New" or "Revised" License

Dart 93.13% Kotlin 0.02% Swift 0.25% Objective-C 0.01% CMake 2.80% C++ 3.33% C 0.21% HTML 0.27%
bitcoin bitcoin-transaction bitcoin-wallet blockcypher-api mempool multi-signature p2pk p2pkh p2sh p2sh-p2wsh

bitcoin_base's People

Contributors

mrtnetwork avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bitcoin_base's Issues

BItcoin transaction

I'm trying to use this lib as part of a crypto wallet but got stuck in this error:

  final changeAddr = P2pkhAddress(
    address: 'tb1qhtnl5n66h242e580h9sdkz8edjk335j9mrzyxj',
  );

Seems like tb1qhtnl5n66h242e580h9sdkz8edjk335j9mrzyxj has an l that is not in base58 alphabet

Added the test in this fork
https://github.com/ivofernandes/bitcoin_base/blob/main/test/transaction_test.dart

The problem is in the blockchain_utils but at the same time the project is not using the last version of blockchain_utils

Can you help with this?

将bitcoin_base库打包在SDK中,运行没有报错,但是将SDK引入app,运行APP出错

报错内容如下,想请问有遇到类型情况的吗,如何解决;
尝试flutter clean,之后flutter pub get;没有解决

`/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/address/segwit_address.dart:49:29: Error: The getter '$1' isn't defined for the class 'Tuple<int, List>'.

  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
  • 'List' is from 'dart:core'.
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$1'.
    final version = convert.$1;
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/address/segwit_address.dart:53:43: Error: The getter '$2' isn't defined for the class 'Tuple<int, List>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
  • 'List' is from 'dart:core'.
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$2'.
    return BytesUtils.toHexString(convert.$2);
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/input.dart:65:18: Error: The getter '$2' isn't defined for the class 'Tuple<int, int>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$2'.
    cursor += vi.$2;
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/input.dart:65:12: Error: A value of type 'num' can't be assigned to a variable of type 'int'.
    cursor += vi.$2;
    ^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/input.dart:66:72: Error: The getter '$1' isn't defined for the class 'Tuple<int, int>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$1'.
    List unlockingScript = txInputRaw.sublist(cursor, cursor + vi.$1);
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/input.dart:66:67: Error: The argument type 'num' can't be assigned to the parameter type 'int?'.
    List unlockingScript = txInputRaw.sublist(cursor, cursor + vi.$1);
    ^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/input.dart:67:18: Error: The getter '$1' isn't defined for the class 'Tuple<int, int>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$1'.
    cursor += vi.$1;
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/input.dart:67:12: Error: A value of type 'num' can't be assigned to a variable of type 'int'.
    cursor += vi.$1;
    ^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/output.dart:43:18: Error: The getter '$2' isn't defined for the class 'Tuple<int, int>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$2'.
    cursor += vi.$2;
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/output.dart:43:12: Error: A value of type 'num' can't be assigned to a variable of type 'int'.
    cursor += vi.$2;
    ^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/output.dart:44:68: Error: The getter '$1' isn't defined for the class 'Tuple<int, int>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$1'.
    List lockScript = txoutputraw.sublist(cursor, cursor + vi.$1);
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/output.dart:44:63: Error: The argument type 'num' can't be assigned to the parameter type 'int?'.
    List lockScript = txoutputraw.sublist(cursor, cursor + vi.$1);
    ^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/output.dart:45:18: Error: The getter '$1' isn't defined for the class 'Tuple<int, int>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$1'.
    cursor += vi.$1;
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/output.dart:45:12: Error: A value of type 'num' can't be assigned to a variable of type 'int'.
    cursor += vi.$1;
    ^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/script.dart:72:34: Error: The getter '$1' isn't defined for the class 'Tuple<int, int>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$1'.
    int dataSize = viAndSize.$1;
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/script.dart:73:30: Error: The getter '$2' isn't defined for the class 'Tuple<int, int>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$2'.
    int size = viAndSize.$2;
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/transaction.dart:76:18: Error: The getter '$2' isn't defined for the class 'Tuple<int, int>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$2'.
    cursor += vi.$2;
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/transaction.dart:76:12: Error: A value of type 'num' can't be assigned to a variable of type 'int'
    .
    cursor += vi.$2;
    ^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/transaction.dart:79:36: Error: The getter '$1' isn't defined for the class 'Tuple<int, int>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$1'.
    for (int index = 0; index < vi.$1; index++) {
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/transaction.dart:89:21: Error: The getter '$2' isn't defined for the class 'Tuple<int, int>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$2'.
    cursor += viOut.$2;
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/transaction.dart:89:12: Error: A value of type 'num' can't be assigned to a variable of type 'int'
    .
    cursor += viOut.$2;
    ^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/script/transaction.dart:90:39: Error: The getter '$1' isn't defined for the class 'Tuple<int, int>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$1'.
    for (int index = 0; index < viOut.$1; index++) {
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/crypto/keypair/ec_private.dart:24:39: Error: The getter '$1' isn't defined for the class 'Tuple<List, PubKey
    Modes>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
  • 'List' is from 'dart:core'.
  • 'PubKeyModes' is from 'package:blockchain_utils/bip/address/p2pkh_addr.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/bip/address/p2pkh_addr.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$1'.
    return ECPrivate.fromBytes(decode.$1);
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/address/validate.dart:74:27: Error: The getter '$1' isn't defined for the class 'Tuple<List, List>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
  • 'List' is from 'dart:core'.
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$1'.
    if (bytesEqual(decode.$1, netVersion)) {
    ^^
    /C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/bitcoin_base-2.0.1/lib/src/bitcoin/address/validate.dart:75:21: Error: The getter '$2' isn't defined for the class 'Tuple<List, List>'.
  • 'Tuple' is from 'package:blockchain_utils/tuple/tuple.dart' ('/C:/Users/86130/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/blockchain_utils-1.4.1/lib/tuple/tuple.dart').
  • 'List' is from 'dart:core'.
    Try correcting the name to the name of an existing getter, or defining a getter or field named '$2'.
    return decode.$2;
    ^^
    Target kernel_snapshot failed: Exception

FAILURE: Build failed with an exception.

  • Where:
    Script 'D:\workspace\git_soft\flutter\packages\flutter_tools\gradle\src\main\groovy\flutter.groovy' line: 1297

  • What went wrong:
    Execution failed for task ':app:compileFlutterBuildDebug'.

Process 'command 'D:\workspace\git_soft\flutter\bin\flutter.bat'' finished with non-zero exit value 1

  • Try:

Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
Get more help at https://help.gradle.org.
`

i got non-mandatory-script-verify-flag (Invalid Schnorr signature)

i use this code, i receive address for regtest, and change blockchain_utils for support regtest.

Future<void> spendingP2TR(ECPrivate sWallet, ECPrivate rWallet) async {
  // All the steps are the same as in the first tutorial;
  // the only difference is the transaction input type,
  // and we use method `buildP2trTransaction` to create the transaction.
  // we use `signTapRoot` of ECPrivate for signing taproot transaction
  final addr = sWallet.getPublic();
  // P2TR address
  final sender = addr.toTaprootAddress();
  var txHash =
      "d3ff326b6c592916d6fff13aa3a7a3e3b762a80d8bd99b80b9a8c7e9c904ea05";
  var value = BigInt.from(99999780);
  var vout = 1;
  var scriptType = BitcoinAddressType.p2tr;
  var blockHeight = 441;
  final utxo = [
    UtxoWithAddress(
        utxo: BitcoinUtxo(
            txHash: txHash,
            value: value,
            vout: vout,
            scriptType: scriptType,
            blockHeight: blockHeight),
        ownerDetails:
            UtxoAddressDetails(address: sender, publicKey: addr.toHex()))
  ];
  final sumOfUtxo = utxo.sumOfUtxosValue();
  if (sumOfUtxo == BigInt.zero) {
    throw Exception(
        "account does not have any unspent transaction or mybe no confirmed");
  }

  final feeRate = BitcoinFeeRate.fromMempool({
    "fastestFee": 1,
    "halfHourFee": 1,
    "minimumFee": 1,
  });
  final prive = sWallet;

  final recPub = rWallet.getPublic();
  final receiver = recPub.toSegwitAddress();
  final changeAddress = recPub.toSegwitAddress();
  final List<BitcoinAddress> outputsAdress = [receiver, changeAddress];
  final transactionSize = BitcoinTransactionBuilder.estimateTransactionSize(
      utxos: utxo, outputs: outputsAdress, network: network);
  final estimateFee = BigInt.from(transactionSize * 2);
  final canSpend = sumOfUtxo - estimateFee;
  final outPutWithValue = outputsAdress
      .map((e) => BitcoinOutput(
          address: e, value: canSpend ~/ BigInt.from(outputsAdress.length)))
      .toList();

  final transaction = buildP2trTransaction(
    receiver: outPutWithValue,
    sign: (p0, publicKey, sigHash) {
      // Use signTapRoot instead of signInput for the taproot transaction input.
      return prive.signTapRoot(p0, sighash: sigHash, tweak: true);
    },
    utxo: utxo,
  );
  final ser = transaction.serialize();
  final id = transaction.txId();
  print(ser);
}

got error:

non-mandatory-script-verify-flag (Invalid Schnorr signature)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.