forked from dart-bitcoin/bitcoin_flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dart-bitcoin#25 from SFzxc/feature/add_support_seg…
…wit_tx [WIP] Add support segwit tx builder 80%
- Loading branch information
Showing
14 changed files
with
1,023 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'dart:typed_data'; | ||
import '../src/utils/script.dart' as bscript; | ||
import 'templates/pubkeyhash.dart' as pubkeyhash; | ||
import 'templates/pubkey.dart' as pubkey; | ||
import 'templates/witnesspubkeyhash.dart' as witnessPubKeyHash; | ||
|
||
const SCRIPT_TYPES = { | ||
'P2SM': 'multisig', | ||
'NONSTANDARD': 'nonstandard', | ||
'NULLDATA': 'nulldata', | ||
'P2PK': 'pubkey', | ||
'P2PKH': 'pubkeyhash', | ||
'P2SH': 'scripthash', | ||
'P2WPKH': 'witnesspubkeyhash', | ||
'P2WSH': 'witnessscripthash', | ||
'WITNESS_COMMITMENT': 'witnesscommitment' | ||
}; | ||
|
||
String classifyOutput(Uint8List script) { | ||
if (witnessPubKeyHash.outputCheck(script)) return SCRIPT_TYPES['P2WPKH']; | ||
if (pubkeyhash.outputCheck(script)) return SCRIPT_TYPES['P2PKH']; | ||
final chunks = bscript.decompile(script); | ||
if (chunks == null) throw new ArgumentError('Invalid script'); | ||
return SCRIPT_TYPES['NONSTANDARD']; | ||
} | ||
|
||
String classifyInput(Uint8List script) { | ||
final chunks = bscript.decompile(script); | ||
if (chunks == null) throw new ArgumentError('Invalid script'); | ||
if (pubkeyhash.inputCheck(chunks)) return SCRIPT_TYPES['P2PKH']; | ||
if (pubkey.inputCheck(chunks)) return SCRIPT_TYPES['P2PK']; | ||
return SCRIPT_TYPES['NONSTANDARD']; | ||
} | ||
|
||
String classifyWitness(List<Uint8List> script) { | ||
final chunks = bscript.decompile(script); | ||
if (chunks == null) throw new ArgumentError('Invalid script'); | ||
if (witnessPubKeyHash.inputCheck(chunks)) return SCRIPT_TYPES['P2WPKH']; | ||
return SCRIPT_TYPES['NONSTANDARD']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'dart:typed_data'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:bip32/src/utils/ecurve.dart' show isPoint; | ||
import 'package:bs58check/bs58check.dart' as bs58check; | ||
|
||
import '../crypto.dart'; | ||
import '../models/networks.dart'; | ||
import '../payments/index.dart' show PaymentData; | ||
import '../utils/script.dart' as bscript; | ||
import '../utils/constants/op.dart'; | ||
|
||
class P2PK { | ||
PaymentData data; | ||
NetworkType network; | ||
P2PK({@required data, network}) { | ||
this.network = network ?? bitcoin; | ||
this.data = data; | ||
_init(); | ||
} | ||
|
||
_init() { | ||
if (data.output != null) { | ||
if (data.output[data.output.length - 1] != OPS['OP_CHECKSIG']) | ||
throw new ArgumentError('Output is invalid'); | ||
if (!isPoint(data.output.sublist(1, -1))) | ||
throw new ArgumentError('Output pubkey is invalid'); | ||
} | ||
if (data.input != null) { | ||
// TODO | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'dart:typed_data'; | ||
import '../utils/script.dart' as bscript; | ||
import '../utils/constants/op.dart'; | ||
|
||
bool inputCheck(List<dynamic> chunks) { | ||
return chunks.length == 1 && bscript.isCanonicalScriptSignature(chunks[0]); | ||
// return chunks != null && | ||
// chunks.length == 2 && | ||
// bscript.isCanonicalScriptSignature(chunks[0]) && | ||
// bscript.isCanonicalPubKey(chunks[1]); | ||
} | ||
|
||
// bool outputCheck(Uint8List script) { | ||
// final buffer = bscript.compile(script); | ||
// return buffer.length == 25 && | ||
// buffer[0] == OPS['OP_DUP'] && | ||
// buffer[1] == OPS['OP_HASH160'] && | ||
// buffer[2] == 0x14 && | ||
// buffer[23] == OPS['OP_EQUALVERIFY'] && | ||
// buffer[24] == OPS['OP_CHECKSIG']; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'dart:typed_data'; | ||
import '../utils/script.dart' as bscript; | ||
import '../utils/constants/op.dart'; | ||
|
||
bool inputCheck(List<dynamic> chunks) { | ||
return chunks != null && | ||
chunks.length == 2 && | ||
bscript.isCanonicalScriptSignature(chunks[0]) && | ||
bscript.isCanonicalPubKey(chunks[1]); | ||
} | ||
|
||
bool outputCheck(Uint8List script) { | ||
final buffer = bscript.compile(script); | ||
return buffer.length == 25 && | ||
buffer[0] == OPS['OP_DUP'] && | ||
buffer[1] == OPS['OP_HASH160'] && | ||
buffer[2] == 0x14 && | ||
buffer[23] == OPS['OP_EQUALVERIFY'] && | ||
buffer[24] == OPS['OP_CHECKSIG']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'dart:typed_data'; | ||
import '../utils/script.dart' as bscript; | ||
import '../utils/constants/op.dart'; | ||
|
||
bool inputCheck(List<dynamic> chunks) { | ||
return chunks != null && | ||
chunks.length == 2 && | ||
bscript.isCanonicalScriptSignature(chunks[0]) && | ||
bscript.isCanonicalPubKey(chunks[1]); | ||
} | ||
|
||
bool outputCheck(Uint8List script) { | ||
final buffer = bscript.compile(script); | ||
return buffer.length == 22 && | ||
buffer[0] == OPS['OP_0'] && | ||
buffer[1] == 0x14; | ||
} |
Oops, something went wrong.