util func to check if scriptpubkey is a fusion

This commit is contained in:
julian 2023-10-19 16:03:19 -06:00
parent 7e9baccedb
commit ad14c16bcc
2 changed files with 53 additions and 0 deletions

View file

@ -2,8 +2,11 @@ import 'dart:typed_data';
import 'package:bitcoindart/src/utils/constants/op.dart' as op; import 'package:bitcoindart/src/utils/constants/op.dart' as op;
import 'package:bitcoindart/src/utils/script.dart' as bscript; import 'package:bitcoindart/src/utils/script.dart' as bscript;
import 'package:stackwallet/utilities/extensions/impl/string.dart';
abstract final class BchUtils { abstract final class BchUtils {
static const FUSE_ID = 'FUZ\x00';
static bool isSLP(Uint8List scriptPubKey) { static bool isSLP(Uint8List scriptPubKey) {
const id = [83, 76, 80, 0]; // 'SLP\x00' const id = [83, 76, 80, 0]; // 'SLP\x00'
final decompiled = bscript.decompile(scriptPubKey); final decompiled = bscript.decompile(scriptPubKey);
@ -26,4 +29,33 @@ abstract final class BchUtils {
return false; return false;
} }
static bool isFUZE(Uint8List scriptPubKey) {
final id = FUSE_ID.toUint8ListFromUtf8;
final decompiled = bscript.decompile(scriptPubKey);
if (decompiled != null &&
decompiled.length > 2 &&
decompiled.first == op.OPS["OP_RETURN"]) {
// check session hash length. Should be 32 bytes
final sessionHash = decompiled[2];
if (!(sessionHash is List<int> && sessionHash.length == 32)) {
return false;
}
final _id = decompiled[1];
if (_id is List<int> && _id.length == id.length) {
for (int i = 0; i < id.length; i++) {
if (_id[i] != id[i]) {
return false;
}
}
// lists match!
return true;
}
}
return false;
}
} }

View file

@ -22,4 +22,25 @@ void main() {
false, false,
); );
}); });
test("script pub key check for fuze is true", () {
expect(
BchUtils.isFUZE("6a0446555a00204d662fb69f34dc23434a61c7bbb65c9f99a247f9c8"
"b377cb4de3cadf7542f8f0"
.toUint8ListFromHex),
true,
);
});
test("script pub key check for fuze is not true", () {
expect(
BchUtils.isFUZE(
"6a04534c500001010747454e45534953044d5430320f4d757461626c652054657374"
"2030321668747470733a2f2f46756c6c537461636b2e63617368200e9a18"
"8911ec0f2ac10cc9425b457d10ba14151a64eb4640f95ed7dab9e8f62601"
"004c00080000000000000001"
.toUint8ListFromHex),
false,
);
});
} }