mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-03 17:29:23 +00:00
quick and dirty SLP check
This commit is contained in:
parent
be3f82e070
commit
b0338aa76a
2 changed files with 54 additions and 0 deletions
29
lib/services/coins/bitcoincash/bch_utils.dart
Normal file
29
lib/services/coins/bitcoincash/bch_utils.dart
Normal file
|
@ -0,0 +1,29 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:bitcoindart/src/utils/constants/op.dart' as op;
|
||||
import 'package:bitcoindart/src/utils/script.dart' as bscript;
|
||||
|
||||
abstract final class BchUtils {
|
||||
static bool isSLP(Uint8List scriptPubKey) {
|
||||
const id = [83, 76, 80, 0]; // 'SLP\x00'
|
||||
final decompiled = bscript.decompile(scriptPubKey);
|
||||
|
||||
if (decompiled != null &&
|
||||
decompiled.length > 1 &&
|
||||
decompiled.first == op.OPS["OP_RETURN"]) {
|
||||
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;
|
||||
}
|
||||
}
|
25
test/services/coins/bitcoincash/bch_utils_test.dart
Normal file
25
test/services/coins/bitcoincash/bch_utils_test.dart
Normal file
|
@ -0,0 +1,25 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:stackwallet/services/coins/bitcoincash/bch_utils.dart';
|
||||
import 'package:stackwallet/utilities/extensions/impl/string.dart';
|
||||
|
||||
void main() {
|
||||
test("script pub key check for SLP is true", () {
|
||||
expect(
|
||||
BchUtils.isSLP(
|
||||
"6a04534c500001010747454e45534953044d5430320f4d757461626c652054657374"
|
||||
"2030321668747470733a2f2f46756c6c537461636b2e63617368200e9a18"
|
||||
"8911ec0f2ac10cc9425b457d10ba14151a64eb4640f95ed7dab9e8f62601"
|
||||
"004c00080000000000000001"
|
||||
.toUint8ListFromHex),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test("script pub key check for SLP is not true", () {
|
||||
expect(
|
||||
BchUtils.isSLP("76a914a78bb9aa1b54c859b5fe72e6f6f576248b3231c888ac"
|
||||
.toUint8ListFromHex),
|
||||
false,
|
||||
);
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue