Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to include P2PKH and P2WPKH classes in library exports #28

Merged
merged 3 commits into from
Mar 5, 2020

Conversation

RohanKapurDEV
Copy link
Contributor

@RohanKapurDEV RohanKapurDEV commented Mar 4, 2020

Quick edit to library main file to include access to P2PKH class

@RohanKapurDEV RohanKapurDEV changed the title Update to include P2PKH class Update to include P2PKH class in library exports Mar 4, 2020
@longhoangwkm
Copy link
Collaborator

longhoangwkm commented Mar 4, 2020

@RohanKapurDEV why do you wanna to export this class. Could give me a context. And export p2wpkh also if need

@RohanKapurDEV
Copy link
Contributor Author

RohanKapurDEV commented Mar 4, 2020

I wrote the following code while exploring how the library works:
I had to add that line to use P2PKH class.

import 'package:bip32/bip32.dart' as bip32;
import 'package:bip39/bip39.dart' as bip39;
import 'package:bitcoin_flutter/bitcoin_flutter.dart';
import 'package:bitcoin_flutter/src/models/networks.dart';
import 'package:flutter/material.dart';


class WalletService extends ChangeNotifier{
  final entropy = '';

  bip44test() {
    final mnemonic = bip39.generateMnemonic();
    final seed = bip39.mnemonicToSeed(mnemonic);
    final root = bip32.BIP32.fromSeed(seed);

    final node1 = root.derivePath("m/44'/0'/0'/0/0"); // (m/ purpose' / coin_type' / account_index' / chain(external_or_change) / address_index(external_or_change))
    final node2 = root.derivePath("m/44'/0'/0'/0/1");
    final node3 = root.derivePath("m/44'/0'/0'/0/2");

    final address1 = P2PKH(data: new P2PKHData(pubkey: node1.publicKey)).data.address; 
    final address2 = P2PKH(data: new P2PKHData(pubkey: node2.publicKey)).data.address; 
    final address3 = P2PKH(data: new P2PKHData(pubkey: node3.publicKey)).data.address; 
    
    final changeNode1 = root.derivePath("m/44'/0'/0'/1/0"); 
    final changeNode2 = root.derivePath("m/44'/0'/0'/1/1"); 
    final changeNode3 = root.derivePath("m/44'/0'/0'/1/2");

    final changeAddress1 = P2PKH(data: new P2PKHData(pubkey: changeNode1.publicKey)).data.address; 
    final changeAddress2 = P2PKH(data: new P2PKHData(pubkey: changeNode2.publicKey)).data.address; 
    final changeAddress3 = P2PKH(data: new P2PKHData(pubkey: changeNode3.publicKey)).data.address; 

    print('''
    BIP39 Mnemonic: $mnemonic
    BIP32 Master Node: $root
    
    BIP44 Receiving Address 1: $address1
    BIP44 Receiving Address 2: $address2
    BIP44 Receiving Address 3: $address3

    BIP44 Change Address 1: $changeAddress1
    BIP44 Change Address 1: $changeAddress2
    BIP44 Change Address 1: $changeAddress3
    ''');
  }
}

@RohanKapurDEV
Copy link
Contributor Author

It is just random test code, not to be used in any real app. Only for exploring library

@longhoangwkm
Copy link
Collaborator

longhoangwkm commented Mar 4, 2020

i see, please help me export p2wpkh.dart also

btw, Using fenced-code-blocks to embed code

@RohanKapurDEV
Copy link
Contributor Author

Ok, p2wpkh has also been added!

@longhoangwkm
Copy link
Collaborator

longhoangwkm commented Mar 4, 2020

just run test. 1 failed.
Help me move final EMPTY_SCRIPT = Uint8List.fromList([]);at lib/src/payments/p2wpkh.dart go inside P2WPKH class. Because EMPTY_SCRIPT already exported at transaction.dart

$ pub run test

00:10 +97 -1: loading test/bitcoin_test.dart [E]
  Failed to load "test/bitcoin_test.dart":
  Unable to spawn isolate: lib/bitcoin_flutter.dart:12:1: Error: 'EMPTY_SCRIPT' is exported from both 'package:bitcoin_flutter/src/transaction.dart' and 'package:bitcoin_flutter/src/payments/p2wpkh.dart'.
  export 'src/payments/p2wpkh.dart';

P/s: We should run test before pushing code

@RohanKapurDEV
Copy link
Contributor Author

RohanKapurDEV commented Mar 4, 2020

P2WPKH class has been updated to include EMPTY_SCRIPT. I know I should be running all tests but i've been updating the lib from inside the GitHub editor due to my personal laptop being in a repair shop for a few days.

I'll start runnning tests with each commit when I get it back for sure

@RohanKapurDEV RohanKapurDEV changed the title Update to include P2PKH class in library exports Updates to include P2PKH and P2WPKH classes in library exports Mar 4, 2020
@longhoangwkm
Copy link
Collaborator

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants