Skip to content

Commit 5f2fcdc

Browse files
authored
Merge pull request #72 from twostack/uint64-fixes
Bugfix: Uint64 error when using with Flutter Web
2 parents 8d8b380 + a78a978 commit 5f2fcdc

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

lib/src/encoding/utils.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ BigInt readVarInt(Uint8List buffer) {
176176
Uint8List encodeBigIntSV(BigInt number) {
177177
int size = (number.bitLength + 7) >> 3;
178178

179+
if (size == 0) size = 8; //always padd to 64 bits if zero
180+
179181
var result = Uint8List(size);
180182
for (int i = 0; i < size; i++) {
181183
result[size - i - 1] = (number & _byteMask).toInt();

lib/src/sighash.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class Sighash {
324324
writer.write(subscript.buffer);
325325

326326
// value of the output spent by this input (8-byte little endian)
327-
writer.writeUint64(satoshis.toInt(), Endian.little);
327+
writer.write(encodeBigIntSV(satoshis));
328328

329329
// nSequence of the input (4-byte little endian)
330330
var sequenceNumber = input.sequenceNumber;

lib/src/transaction/transaction_output.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class TransactionOutput {
3737
/// being used.
3838
TransactionOutput.fromReader(ByteDataReader reader) {
3939

40-
this.satoshis = BigInt.from(reader.readUint64(Endian.little));
40+
var buffer = reader.read(8);
41+
this.satoshis = castToBigInt(buffer, false, nMaxNumSize: 8);
4142
var size = readVarIntNum(reader);
4243
if (size != 0) {
4344
_script = SVScript.fromBuffer(reader.read(size, copy: true));

0 commit comments

Comments
 (0)