-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpc: add withdrawal bundle data fetching
- Loading branch information
1 parent
0cab502
commit 2303864
Showing
7 changed files
with
288 additions
and
34 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
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
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,128 @@ | ||
class RawTransaction { | ||
final String txid; | ||
final String hash; | ||
final int size; | ||
final int vsize; | ||
final int version; | ||
final int locktime; | ||
final List<Vin> vin; | ||
final List<Vout> vout; | ||
|
||
RawTransaction({ | ||
required this.txid, | ||
required this.hash, | ||
required this.size, | ||
required this.vsize, | ||
required this.version, | ||
required this.locktime, | ||
required this.vin, | ||
required this.vout, | ||
}); | ||
|
||
factory RawTransaction.fromJson(Map<String, dynamic> json) { | ||
return RawTransaction( | ||
txid: json['txid'], | ||
hash: json['hash'], | ||
size: json['size'], | ||
vsize: json['vsize'], | ||
version: json['version'], | ||
locktime: json['locktime'], | ||
vin: (json['vin'] as List).map((e) => Vin.fromJson(e)).toList(), | ||
vout: (json['vout'] as List).map((e) => Vout.fromJson(e)).toList(), | ||
); | ||
} | ||
} | ||
|
||
class Vin { | ||
final String txid; | ||
final int vout; | ||
final ScriptSig scriptSig; | ||
final List<String>? txinwitness; | ||
final int sequence; | ||
|
||
Vin({ | ||
required this.txid, | ||
required this.vout, | ||
required this.scriptSig, | ||
this.txinwitness, | ||
required this.sequence, | ||
}); | ||
|
||
factory Vin.fromJson(Map<String, dynamic> json) { | ||
return Vin( | ||
txid: getMapKey(json, 'txid', ''), | ||
vout: getMapKey(json, 'vout', 0), | ||
scriptSig: ScriptSig.fromJson(json['scriptSig']), | ||
txinwitness: json['txinwitness']?.cast<String>(), | ||
sequence: json['sequence'], | ||
); | ||
} | ||
} | ||
|
||
class ScriptSig { | ||
final String asm; | ||
final String hex; | ||
|
||
ScriptSig({required this.asm, required this.hex}); | ||
|
||
factory ScriptSig.fromJson(Map<String, dynamic>? json) { | ||
if (json == null) { | ||
return ScriptSig(asm: '', hex: ''); | ||
} | ||
|
||
return ScriptSig( | ||
asm: json['asm'], | ||
hex: json['hex'], | ||
); | ||
} | ||
} | ||
|
||
class Vout { | ||
final double value; | ||
final int n; | ||
final ScriptPubKey scriptPubKey; | ||
|
||
Vout({required this.value, required this.n, required this.scriptPubKey}); | ||
|
||
factory Vout.fromJson(Map<String, dynamic> json) { | ||
return Vout( | ||
value: json['value'], | ||
n: json['n'], | ||
scriptPubKey: ScriptPubKey.fromJson(json['scriptPubKey']), | ||
); | ||
} | ||
} | ||
|
||
class ScriptPubKey { | ||
final String asm; | ||
final String hex; | ||
final int reqSigs; | ||
final String type; | ||
final List<String> addresses; | ||
|
||
ScriptPubKey({ | ||
required this.asm, | ||
required this.hex, | ||
required this.reqSigs, | ||
required this.type, | ||
required this.addresses, | ||
}); | ||
|
||
factory ScriptPubKey.fromJson(Map<String, dynamic> json) { | ||
return ScriptPubKey( | ||
asm: json['asm'], | ||
hex: json['hex'], | ||
reqSigs: getMapKey(json, 'reqSigs', 0), | ||
type: json['type'], | ||
addresses: List<String>.from(json['addresses'] ?? []), | ||
); | ||
} | ||
} | ||
|
||
dynamic getMapKey(Map<String, dynamic> json, String key, fallback) { | ||
if (json.containsKey(key)) { | ||
return json[key]; | ||
} | ||
|
||
return fallback; | ||
} |
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
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,64 @@ | ||
import 'package:sidesail/rpc/rpc_rawtx.dart'; | ||
|
||
class WithdrawalBundle { | ||
WithdrawalBundle({ | ||
required this.hash, | ||
required this.bundleSize, | ||
required this.blockHeight, | ||
required this.withdrawals, | ||
}); | ||
|
||
factory WithdrawalBundle.fromRawTransaction( | ||
RawTransaction tx, | ||
) => | ||
WithdrawalBundle( | ||
hash: tx.hash, | ||
bundleSize: tx.size * 4, | ||
blockHeight: 0, // TODO: how to get this | ||
withdrawals: tx.vout | ||
// filter out OP_RETURN | ||
.where((out) => out.scriptPubKey.type != 'nulldata') | ||
.map( | ||
(out) => Withdrawal( | ||
mainchainFeesSatoshi: 0, // TODO: how to get this | ||
amountSatoshi: (out.value * 100 * 1000 * 1000).toInt(), | ||
address: out.scriptPubKey.addresses.first, | ||
), | ||
) | ||
.toList(), | ||
); | ||
|
||
final String hash; | ||
|
||
final int bundleSize; | ||
final int maxBundleSize = 50 * 1000; | ||
|
||
/// Block number this withdrawal bundle was initiated. | ||
final int blockHeight; | ||
|
||
final List<Withdrawal> withdrawals; | ||
} | ||
|
||
/// A collection of withdrawals that have not yet been proposed into | ||
/// a mainchain withdrawal bundle. | ||
class FutureWithdrawalBundle { | ||
FutureWithdrawalBundle({ | ||
required this.cumulativeWeight, | ||
required this.withdrawals, | ||
}); | ||
|
||
final int cumulativeWeight; | ||
final List<Withdrawal> withdrawals; | ||
} | ||
|
||
class Withdrawal { | ||
Withdrawal({ | ||
required this.mainchainFeesSatoshi, | ||
required this.amountSatoshi, | ||
required this.address, | ||
}); | ||
|
||
final int mainchainFeesSatoshi; // TODO: how to obtain? | ||
final int amountSatoshi; | ||
final String address; | ||
} |
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
Oops, something went wrong.