2021-05-07 07:36:38 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-08-25 16:32:40 +00:00
|
|
|
import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
|
|
|
|
import 'package:crypto/crypto.dart';
|
|
|
|
|
2021-05-07 07:36:38 +00:00
|
|
|
String scriptHash(String address, {@required bitcoin.NetworkType networkType}) {
|
|
|
|
final outputScript =
|
|
|
|
bitcoin.Address.addressToOutputScript(address, networkType);
|
|
|
|
final parts = sha256.convert(outputScript).toString().split('');
|
2020-08-25 16:32:40 +00:00
|
|
|
var res = '';
|
|
|
|
|
2021-05-07 07:36:38 +00:00
|
|
|
for (var i = parts.length - 1; i >= 0; i--) {
|
|
|
|
final char = parts[i];
|
2020-08-25 16:32:40 +00:00
|
|
|
i--;
|
2021-05-07 07:36:38 +00:00
|
|
|
final nextChar = parts[i];
|
2020-08-25 16:32:40 +00:00
|
|
|
res += nextChar;
|
|
|
|
res += char;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2021-05-07 07:36:38 +00:00
|
|
|
}
|