diff --git a/Cargo.lock b/Cargo.lock index abb3855..1593c1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -332,9 +332,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.36" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a265e3abeffdce30b2e26b7a11b222fe37c6067404001b434101457d0385eb92" +checksum = "caae68055714ff28740f310927e04f2eba76ff580b16fb18ed90073ee71646f7" dependencies = [ "proc-macro2", "quote 1.0.7", @@ -1721,12 +1721,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "half" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177" - [[package]] name = "hash-db" version = "0.15.2" @@ -5400,16 +5394,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde_cbor" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622" -dependencies = [ - "half", - "serde", -] - [[package]] name = "serde_derive" version = "1.0.115" @@ -6406,7 +6390,7 @@ dependencies = [ [[package]] name = "substrate-subxt" version = "0.11.0" -source = "git+https://github.com/dvc94ch/substrate-subxt?branch=fix-port#5c34446e0ad1afd64b03400f21ad2e4bec84cc2b" +source = "git+https://github.com/dvc94ch/substrate-subxt?branch=different-assert#0323b5891996e373d3c17488b5e124011488c788" dependencies = [ "frame-metadata", "frame-support", @@ -6434,7 +6418,7 @@ dependencies = [ [[package]] name = "substrate-subxt-client" version = "0.3.0" -source = "git+https://github.com/dvc94ch/substrate-subxt?branch=fix-port#5c34446e0ad1afd64b03400f21ad2e4bec84cc2b" +source = "git+https://github.com/dvc94ch/substrate-subxt?branch=different-assert#0323b5891996e373d3c17488b5e124011488c788" dependencies = [ "async-std", "futures 0.1.29", @@ -6451,7 +6435,7 @@ dependencies = [ [[package]] name = "substrate-subxt-proc-macro" version = "0.11.0" -source = "git+https://github.com/dvc94ch/substrate-subxt?branch=fix-port#5c34446e0ad1afd64b03400f21ad2e4bec84cc2b" +source = "git+https://github.com/dvc94ch/substrate-subxt?branch=different-assert#0323b5891996e373d3c17488b5e124011488c788" dependencies = [ "heck", "proc-macro-crate", @@ -6484,6 +6468,7 @@ checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1" name = "sunshine" version = "0.1.0" dependencies = [ + "async-std", "frusty-logger", "log", "sunshine-bounty-ffi", @@ -6495,7 +6480,7 @@ dependencies = [ [[package]] name = "sunshine-bank" version = "0.2.0" -source = "git+https://github.com/sunshine-protocol/sunshine-bounty#a9e034afa96df0ff21b4e9540838019f944d3032" +source = "git+https://github.com/sunshine-protocol/sunshine-bounty#b470a6802069d2b6ba31bcac4bc52e02bd8763aa" dependencies = [ "clear_on_drop", "frame-support", @@ -6512,7 +6497,7 @@ dependencies = [ [[package]] name = "sunshine-bounty" version = "0.2.1" -source = "git+https://github.com/sunshine-protocol/sunshine-bounty#a9e034afa96df0ff21b4e9540838019f944d3032" +source = "git+https://github.com/sunshine-protocol/sunshine-bounty#b470a6802069d2b6ba31bcac4bc52e02bd8763aa" dependencies = [ "clear_on_drop", "frame-support", @@ -6526,7 +6511,7 @@ dependencies = [ [[package]] name = "sunshine-bounty-client" version = "0.2.0" -source = "git+https://github.com/sunshine-protocol/sunshine-bounty#a9e034afa96df0ff21b4e9540838019f944d3032" +source = "git+https://github.com/sunshine-protocol/sunshine-bounty#b470a6802069d2b6ba31bcac4bc52e02bd8763aa" dependencies = [ "async-std", "frame-support", @@ -6538,18 +6523,20 @@ dependencies = [ "substrate-subxt", "sunshine-bounty-utils", "sunshine-client-utils", + "sunshine-faucet-client", + "sunshine-identity-client", "thiserror", ] [[package]] name = "sunshine-bounty-ffi" version = "0.1.0" -source = "git+https://github.com/sunshine-protocol/sunshine-bounty#a9e034afa96df0ff21b4e9540838019f944d3032" +source = "git+https://github.com/sunshine-protocol/sunshine-bounty#b470a6802069d2b6ba31bcac4bc52e02bd8763aa" dependencies = [ "anyhow", "ipld-block-builder", "serde", - "serde_cbor", + "serde_json", "substrate-subxt", "sunshine-bounty-client", "sunshine-client-utils", @@ -6559,7 +6546,7 @@ dependencies = [ [[package]] name = "sunshine-bounty-utils" version = "0.2.0" -source = "git+https://github.com/sunshine-protocol/sunshine-bounty#a9e034afa96df0ff21b4e9540838019f944d3032" +source = "git+https://github.com/sunshine-protocol/sunshine-bounty#b470a6802069d2b6ba31bcac4bc52e02bd8763aa" dependencies = [ "clear_on_drop", "derive-new", @@ -6574,7 +6561,7 @@ dependencies = [ [[package]] name = "sunshine-client" version = "0.1.0" -source = "git+https://github.com/sunshine-protocol/sunshine#71a055d80236f8b401f1fd38f55d676c47d06442" +source = "git+https://github.com/sunshine-protocol/sunshine#13e7ca5dd5715ec9607689592e218bc56269e58f" dependencies = [ "async-trait", "ipld-block-builder", @@ -6591,7 +6578,7 @@ dependencies = [ [[package]] name = "sunshine-client-utils" version = "0.1.0" -source = "git+https://github.com/sunshine-protocol/sunshine-core#2b92b5432a21a429c17bdafefae2c278ceeeb2de" +source = "git+https://github.com/sunshine-protocol/sunshine-core#b15fa47a17ea53107598332f9fc8c99d0b9dab75" dependencies = [ "anyhow", "async-std", @@ -6613,7 +6600,7 @@ dependencies = [ [[package]] name = "sunshine-codec" version = "0.1.0" -source = "git+https://github.com/sunshine-protocol/sunshine-core#2b92b5432a21a429c17bdafefae2c278ceeeb2de" +source = "git+https://github.com/sunshine-protocol/sunshine-core#b15fa47a17ea53107598332f9fc8c99d0b9dab75" dependencies = [ "anyhow", "hash-db", @@ -6625,7 +6612,7 @@ dependencies = [ [[package]] name = "sunshine-court" version = "0.2.0" -source = "git+https://github.com/sunshine-protocol/sunshine-bounty#a9e034afa96df0ff21b4e9540838019f944d3032" +source = "git+https://github.com/sunshine-protocol/sunshine-bounty#b470a6802069d2b6ba31bcac4bc52e02bd8763aa" dependencies = [ "clear_on_drop", "frame-support", @@ -6641,7 +6628,7 @@ dependencies = [ [[package]] name = "sunshine-crypto" version = "0.1.0" -source = "git+https://github.com/sunshine-protocol/sunshine-core#2b92b5432a21a429c17bdafefae2c278ceeeb2de" +source = "git+https://github.com/sunshine-protocol/sunshine-core#b15fa47a17ea53107598332f9fc8c99d0b9dab75" dependencies = [ "aead 0.2.0", "anyhow", @@ -6671,7 +6658,7 @@ dependencies = [ [[package]] name = "sunshine-donate" version = "0.2.0" -source = "git+https://github.com/sunshine-protocol/sunshine-bounty#a9e034afa96df0ff21b4e9540838019f944d3032" +source = "git+https://github.com/sunshine-protocol/sunshine-bounty#b470a6802069d2b6ba31bcac4bc52e02bd8763aa" dependencies = [ "clear_on_drop", "frame-support", @@ -6686,7 +6673,7 @@ dependencies = [ [[package]] name = "sunshine-faucet-client" version = "0.2.0" -source = "git+https://github.com/sunshine-protocol/sunshine-identity#34a84141f464ce307bb2fe027dca7513c5591e86" +source = "git+https://github.com/sunshine-protocol/sunshine-identity#73795b06d34b5082ec298a5a726107d87c1dfd91" dependencies = [ "parity-scale-codec", "substrate-subxt", @@ -6697,7 +6684,7 @@ dependencies = [ [[package]] name = "sunshine-faucet-ffi" version = "0.1.0" -source = "git+https://github.com/sunshine-protocol/sunshine-identity#34a84141f464ce307bb2fe027dca7513c5591e86" +source = "git+https://github.com/sunshine-protocol/sunshine-identity#73795b06d34b5082ec298a5a726107d87c1dfd91" dependencies = [ "substrate-subxt", "sunshine-client-utils", @@ -6709,7 +6696,7 @@ dependencies = [ [[package]] name = "sunshine-faucet-pallet" version = "0.2.0" -source = "git+https://github.com/sunshine-protocol/sunshine-identity#34a84141f464ce307bb2fe027dca7513c5591e86" +source = "git+https://github.com/sunshine-protocol/sunshine-identity#73795b06d34b5082ec298a5a726107d87c1dfd91" dependencies = [ "frame-support", "frame-system", @@ -6723,7 +6710,7 @@ dependencies = [ [[package]] name = "sunshine-ffi-utils" version = "0.1.0" -source = "git+https://github.com/sunshine-protocol/sunshine-core#2b92b5432a21a429c17bdafefae2c278ceeeb2de" +source = "git+https://github.com/sunshine-protocol/sunshine-core#b15fa47a17ea53107598332f9fc8c99d0b9dab75" dependencies = [ "allo-isolate", "async-std", @@ -6734,7 +6721,7 @@ dependencies = [ [[package]] name = "sunshine-identity-client" version = "0.2.3" -source = "git+https://github.com/sunshine-protocol/sunshine-identity#34a84141f464ce307bb2fe027dca7513c5591e86" +source = "git+https://github.com/sunshine-protocol/sunshine-identity#73795b06d34b5082ec298a5a726107d87c1dfd91" dependencies = [ "async-std", "frame-support", @@ -6753,7 +6740,7 @@ dependencies = [ [[package]] name = "sunshine-identity-ffi" version = "0.2.3" -source = "git+https://github.com/sunshine-protocol/sunshine-identity#34a84141f464ce307bb2fe027dca7513c5591e86" +source = "git+https://github.com/sunshine-protocol/sunshine-identity#73795b06d34b5082ec298a5a726107d87c1dfd91" dependencies = [ "substrate-subxt", "sunshine-client-utils", @@ -6765,7 +6752,7 @@ dependencies = [ [[package]] name = "sunshine-identity-pallet" version = "0.2.0" -source = "git+https://github.com/sunshine-protocol/sunshine-identity#34a84141f464ce307bb2fe027dca7513c5591e86" +source = "git+https://github.com/sunshine-protocol/sunshine-identity#73795b06d34b5082ec298a5a726107d87c1dfd91" dependencies = [ "frame-support", "frame-system", @@ -6779,7 +6766,7 @@ dependencies = [ [[package]] name = "sunshine-keystore" version = "0.1.0" -source = "git+https://github.com/sunshine-protocol/sunshine-core#2b92b5432a21a429c17bdafefae2c278ceeeb2de" +source = "git+https://github.com/sunshine-protocol/sunshine-core#b15fa47a17ea53107598332f9fc8c99d0b9dab75" dependencies = [ "anyhow", "async-std", @@ -6794,7 +6781,7 @@ dependencies = [ [[package]] name = "sunshine-node" version = "0.1.0" -source = "git+https://github.com/sunshine-protocol/sunshine#71a055d80236f8b401f1fd38f55d676c47d06442" +source = "git+https://github.com/sunshine-protocol/sunshine#13e7ca5dd5715ec9607689592e218bc56269e58f" dependencies = [ "futures 0.3.5", "hex-literal", @@ -6825,7 +6812,7 @@ dependencies = [ [[package]] name = "sunshine-org" version = "0.2.0" -source = "git+https://github.com/sunshine-protocol/sunshine-bounty#a9e034afa96df0ff21b4e9540838019f944d3032" +source = "git+https://github.com/sunshine-protocol/sunshine-bounty#b470a6802069d2b6ba31bcac4bc52e02bd8763aa" dependencies = [ "clear_on_drop", "frame-support", @@ -6841,7 +6828,7 @@ dependencies = [ [[package]] name = "sunshine-pallet-utils" version = "0.1.0" -source = "git+https://github.com/sunshine-protocol/sunshine-core#2b92b5432a21a429c17bdafefae2c278ceeeb2de" +source = "git+https://github.com/sunshine-protocol/sunshine-core#b15fa47a17ea53107598332f9fc8c99d0b9dab75" dependencies = [ "blake2-rfc", "hash-db", @@ -6855,7 +6842,7 @@ dependencies = [ [[package]] name = "sunshine-runtime" version = "0.1.0" -source = "git+https://github.com/sunshine-protocol/sunshine#71a055d80236f8b401f1fd38f55d676c47d06442" +source = "git+https://github.com/sunshine-protocol/sunshine#13e7ca5dd5715ec9607689592e218bc56269e58f" dependencies = [ "frame-executive", "frame-support", @@ -6897,7 +6884,7 @@ dependencies = [ [[package]] name = "sunshine-treasury" version = "0.0.1" -source = "git+https://github.com/sunshine-protocol/sunshine-bounty#a9e034afa96df0ff21b4e9540838019f944d3032" +source = "git+https://github.com/sunshine-protocol/sunshine-bounty#b470a6802069d2b6ba31bcac4bc52e02bd8763aa" dependencies = [ "clear_on_drop", "frame-support", @@ -6911,7 +6898,7 @@ dependencies = [ [[package]] name = "sunshine-vote" version = "0.2.0" -source = "git+https://github.com/sunshine-protocol/sunshine-bounty#a9e034afa96df0ff21b4e9540838019f944d3032" +source = "git+https://github.com/sunshine-protocol/sunshine-bounty#b470a6802069d2b6ba31bcac4bc52e02bd8763aa" dependencies = [ "clear_on_drop", "frame-support", diff --git a/Cargo.toml b/Cargo.toml index a1ba377..c917adb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,4 +2,12 @@ members = ["native/*"] [patch.crates-io] -substrate-subxt = { git = "https://github.com/dvc94ch/substrate-subxt", branch = "fix-port" } +substrate-subxt = { git = "https://github.com/dvc94ch/substrate-subxt", branch = "different-assert" } + +# [profile.dev] +# panic = 'abort' + +# [profile.release] +# lto = true +# panic = 'abort' +# codegen-units = 1 \ No newline at end of file diff --git a/lib/screens/bounty_screen.dart b/lib/screens/bounty_screen.dart index 5969029..61db03c 100644 --- a/lib/screens/bounty_screen.dart +++ b/lib/screens/bounty_screen.dart @@ -375,7 +375,7 @@ class _BountyHeader extends StatelessWidget { child: FittedBox( fit: BoxFit.fitWidth, child: Text( - numberFormat.format(bounty.info.total), + numberFormat.format(bounty.info.total.toInt()), style: TextStyle( color: const Color(0xFF25C100), fontSize: 14.ssp.toDouble(), diff --git a/lib/screens/create_bounty_screen.dart b/lib/screens/create_bounty_screen.dart index 9f8f9d2..2624fe3 100644 --- a/lib/screens/create_bounty_screen.dart +++ b/lib/screens/create_bounty_screen.dart @@ -94,9 +94,9 @@ class _CreateBountyScreenState extends State { data.owner, data.repo, data.issue, - int.parse(_amountController.text), + BigInt.parse(_amountController.text), ); - print(id); + print('Created Bounty with Id: $id'); await Future.delayed( const Duration(milliseconds: 50), () { diff --git a/lib/screens/intro_screen.dart b/lib/screens/intro_screen.dart index 6c8c35e..48502d1 100644 --- a/lib/screens/intro_screen.dart +++ b/lib/screens/intro_screen.dart @@ -49,14 +49,15 @@ class _IntroScreenState extends State { ExtendedNavigator.root.push(Routes.generateAccountStepTwoScreen); }, ), - SizedBox(height: 20.h.toDouble()), - Button( - variant: ButtonVariant.primary, - text: 'Restore my account', - onPressed: () { - ExtendedNavigator.root.push(Routes.recoverAccountStepTwoScreen); - }, - ), + // SizedBox(height: 20.h.toDouble()), + // Button( + // variant: ButtonVariant.primary, + // text: 'Restore my account', + // onPressed: () { + // ignore: lines_longer_than_80_chars + // ExtendedNavigator.root.push(Routes.recoverAccountStepTwoScreen); + // }, + // ), ], ), ); diff --git a/lib/screens/main_screen.dart b/lib/screens/main_screen.dart index dfa365b..76d33f0 100644 --- a/lib/screens/main_screen.dart +++ b/lib/screens/main_screen.dart @@ -57,7 +57,7 @@ class _MainScreenState extends State { child: FutureBuilder>( initialData: const [], builder: _buildList, - future: bountyService.listOpenBounties(0), + future: bountyService.listOpenBounties(BigInt.one), ), ), ); @@ -78,10 +78,10 @@ class _MainScreenState extends State { child: BountyItem( bounty: Bounty( info: BountyInformation( - issueNumber: i + 1, + issueNumber: BigInt.from(i) + BigInt.one, repoName: 'sunshine', repoOwner: 'sunshine', - total: 100, + total: BigInt.from(1000), ), issue: GithubIssue( createdAt: DateTime.now(), diff --git a/lib/screens/submit_for_bounty_screen.dart b/lib/screens/submit_for_bounty_screen.dart index ac9273b..89de2f7 100644 --- a/lib/screens/submit_for_bounty_screen.dart +++ b/lib/screens/submit_for_bounty_screen.dart @@ -99,9 +99,9 @@ class _SubmitForBountyScreenState extends State { data.owner, data.repo, data.issue, - int.parse(_amountController.text), + BigInt.parse(_amountController.text), ); - print(id); + print('Submitted for bounty with: $id'); await Future.delayed( const Duration(milliseconds: 50), () { diff --git a/lib/screens/wallet_transfer_screen.dart b/lib/screens/wallet_transfer_screen.dart index d9da0e4..6d734bc 100644 --- a/lib/screens/wallet_transfer_screen.dart +++ b/lib/screens/wallet_transfer_screen.dart @@ -145,7 +145,7 @@ class _WalletTransferConfirmationScreenState try { await _walletService.transfer( widget.id, - int.parse(widget.amount), + BigInt.parse(widget.amount), ); await Future.delayed( const Duration(milliseconds: 100), diff --git a/lib/services/bounty_service.dart b/lib/services/bounty_service.dart index 5a79d05..89aeb0a 100644 --- a/lib/services/bounty_service.dart +++ b/lib/services/bounty_service.dart @@ -14,12 +14,12 @@ class BountyService { final ClientService _clientService; final GithubService _githubService; - Future getBounty(int bountyId) async { + Future getBounty(BigInt bountyId) async { final info = await _clientService.getBounty(bountyId); final issue = await _githubService.getIssue( info.repoOwner, info.repoName, - info.issueNumber, + info.issueNumber.toInt(), ); if (issue == null) { return null; @@ -27,12 +27,12 @@ class BountyService { return Bounty(info: info, issue: issue); } - Future getSubmission(int submissionId) async { + Future getSubmission(BigInt submissionId) async { final info = await _clientService.getSubmission(submissionId); final issue = await _githubService.getIssue( info.repoOwner, info.repoName, - info.issueNumber, + info.issueNumber.toInt(), ); if (issue == null) { return null; @@ -40,14 +40,14 @@ class BountyService { return BountySubmission(info: info, issue: issue); } - Future> listOpenBounties(int min) async { + Future> listOpenBounties(BigInt min) async { final list = await _clientService.listOpenBounties(min); final result = []; for (final info in list) { final issue = await _githubService.getIssue( info.repoOwner, info.repoName, - info.issueNumber, + info.issueNumber.toInt(), ); if (issue == null) { continue; @@ -58,7 +58,7 @@ class BountyService { } Future> listBountySubmissions( - int bountyId, + BigInt bountyId, ) async { final list = await _clientService.listBountySubmissions(bountyId); final result = []; @@ -66,7 +66,7 @@ class BountyService { final issue = await _githubService.getIssue( info.repoOwner, info.repoName, - info.issueNumber, + info.issueNumber.toInt(), ); if (issue == null) { return null; @@ -76,11 +76,11 @@ class BountyService { return result; } - Future postBounty( + Future postBounty( String repoOwner, String repoName, - int issueNumber, - int amount, + BigInt issueNumber, + BigInt amount, ) { return _clientService.postBounty( repoOwner, @@ -90,12 +90,12 @@ class BountyService { ); } - Future submitForBounty( - int bountyId, + Future submitForBounty( + BigInt bountyId, String repoOwner, String repoName, - int issueNumber, - int amount, + BigInt issueNumber, + BigInt amount, ) { return _clientService.submitForBounty( bountyId, @@ -106,11 +106,11 @@ class BountyService { ); } - Future approveBounty(int submissionId) { + Future approveBounty(BigInt submissionId) { return _clientService.approveBounty(submissionId); } - Future contibuteToBounty(int bountyId, int amount) { + Future contibuteToBounty(BigInt bountyId, BigInt amount) { return _clientService.contibuteToBounty(bountyId, amount); } } diff --git a/lib/services/client/client_service.dart b/lib/services/client/client_service.dart index 2325dae..9f6d391 100644 --- a/lib/services/client/client_service.dart +++ b/lib/services/client/client_service.dart @@ -8,27 +8,27 @@ abstract class ClientService { Future uid(); Future hasKey(); Future balance(); - Future transfer(String id, int amount); - Future mint(); - Future getBounty(int bountyId); - Future getSubmission(int submissionId); - Future> listOpenBounties(int min); + Future transfer(String id, BigInt amount); + Future mint(); + Future getBounty(BigInt bountyId); + Future getSubmission(BigInt submissionId); + Future> listOpenBounties(BigInt min); Future> listBountySubmissions( - int bountyId, + BigInt bountyId, ); - Future postBounty( + Future postBounty( String repoOwner, String repoName, - int issueNumber, - int amount, + BigInt issueNumber, + BigInt amount, ); - Future submitForBounty( - int bountyId, + Future submitForBounty( + BigInt bountyId, String repoOwner, String repoName, - int issueNumber, - int amount, + BigInt issueNumber, + BigInt amount, ); - Future approveBounty(int submissionId); - Future contibuteToBounty(int bountyId, int amount); + Future approveBounty(BigInt submissionId); + Future contibuteToBounty(BigInt bountyId, BigInt amount); } diff --git a/lib/services/client/dev_client_service.dart b/lib/services/client/dev_client_service.dart index cb0e920..0e1e23d 100644 --- a/lib/services/client/dev_client_service.dart +++ b/lib/services/client/dev_client_service.dart @@ -52,7 +52,7 @@ class DevClientService implements ClientService { } @override - Future transfer(String id, int amount) { + Future transfer(String id, BigInt amount) { throw UnimplementedError(); } @@ -62,24 +62,24 @@ class DevClientService implements ClientService { } @override - Future mint() async { + Future mint() async { _balance = (int.parse(_balance) + 1000000).toString(); - return 1000000; + return BigInt.from(1000000); } @override - Future approveBounty(int submissionId) async { + Future approveBounty(BigInt submissionId) async { return '1000'; } @override - Future contibuteToBounty(int bountyId, int amount) async { + Future contibuteToBounty(BigInt bountyId, BigInt amount) async { final bounty = await getBounty(bountyId); return bounty?.contibute(amount).toString() ?? '0'; } @override - Future getBounty(int bountyId) async { + Future getBounty(BigInt bountyId) async { return _mockedBounties.firstWhere( (e) => e.id == bountyId, orElse: () => null, @@ -87,7 +87,7 @@ class DevClientService implements ClientService { } @override - Future getSubmission(int submissionId) async { + Future getSubmission(BigInt submissionId) async { return _mockedSubmissions.firstWhere( (e) => e.id == submissionId, orElse: () => null, @@ -96,7 +96,7 @@ class DevClientService implements ClientService { @override Future> listBountySubmissions( - int bountyId, + BigInt bountyId, ) async { await Future.delayed(const Duration(milliseconds: 1200)); return _mockedSubmissions.where((e) => e.bountyId == bountyId).toList() @@ -104,23 +104,23 @@ class DevClientService implements ClientService { } @override - Future> listOpenBounties(int min) async { + Future> listOpenBounties(BigInt min) async { await Future.delayed(const Duration(milliseconds: 1200)); return _mockedBounties.where((e) => e.total >= min).toList() ..sort((a, b) => a.id.compareTo(b.id)); } @override - Future postBounty( + Future postBounty( String repoOwner, String repoName, - int issueNumber, - int amount, + BigInt issueNumber, + BigInt amount, ) async { final last = _mockedBounties.last; final v = BountyInformation( depositer: await uid(), - id: last.id + 1, + id: last.id + BigInt.from(1), issueNumber: issueNumber, repoName: repoName, repoOwner: repoOwner, @@ -131,12 +131,12 @@ class DevClientService implements ClientService { } @override - Future submitForBounty( - int bountyId, + Future submitForBounty( + BigInt bountyId, String repoOwner, String repoName, - int issueNumber, - int amount, + BigInt issueNumber, + BigInt amount, ) async { final last = _mockedSubmissions.last; final v = BountySubmissionInformation( @@ -157,59 +157,59 @@ class DevClientService implements ClientService { final List _mockedBounties = [ BountyInformation( - id: 1, + id: BigInt.from(1), depositer: '1', - total: 5595, + total: BigInt.from(5595), repoOwner: 'bluzelle', repoName: 'swarm-of-duty', - issueNumber: 2, + issueNumber: BigInt.from(2), ), BountyInformation( - id: 2, + id: BigInt.from(2), depositer: '1', - total: 22288, + total: BigInt.from(22288), repoOwner: 'aragonone', repoName: 'hack-for-freedom', - issueNumber: 7, + issueNumber: BigInt.from(7), ), BountyInformation( - id: 3, + id: BigInt.from(3), depositer: '1', - total: 100000, + total: BigInt.from(100000), repoOwner: 'ArweaveTeam', repoName: 'Bounties', - issueNumber: 29, + issueNumber: BigInt.from(29), ), BountyInformation( - id: 4, + id: BigInt.from(4), depositer: '1', - total: 15000, + total: BigInt.from(15000), repoOwner: 'ArweaveTeam', repoName: 'Bounties', - issueNumber: 30, + issueNumber: BigInt.from(30), ), ]; final List _mockedSubmissions = [ BountySubmissionInformation( - id: 1, - bountyId: 1, + id: BigInt.from(1), + bountyId: BigInt.from(1), approved: false, awaitingReview: true, submitter: '1', - amount: 6000, + amount: BigInt.from(6000), repoOwner: 'ArweaveTeam', repoName: 'Bounties', - issueNumber: 29, + issueNumber: BigInt.from(29), ), BountySubmissionInformation( - id: 2, - bountyId: 1, + id: BigInt.from(2), + bountyId: BigInt.from(1), approved: false, awaitingReview: true, submitter: '3', - amount: 6000, + amount: BigInt.from(6000), repoOwner: 'ArweaveTeam', repoName: 'Bounties', - issueNumber: 30, + issueNumber: BigInt.from(30), ), ]; diff --git a/lib/services/client/prod_client_service.dart b/lib/services/client/prod_client_service.dart index 25f91c1..2e7f2ff 100644 --- a/lib/services/client/prod_client_service.dart +++ b/lib/services/client/prod_client_service.dart @@ -42,7 +42,7 @@ class ProdClientService implements ClientService { } @override - Future transfer(String id, int amount) { + Future transfer(String id, BigInt amount) { return _sunshineClientService.transfer(id, amount); } @@ -52,7 +52,7 @@ class ProdClientService implements ClientService { } @override - Future mint() { + Future mint() { return _sunshineClientService.mint(); } @@ -62,43 +62,47 @@ class ProdClientService implements ClientService { } @override - Future approveBounty(int submissionId) { + Future approveBounty(BigInt submissionId) { return _sunshineClientService.approveBounty(submissionId); } @override - Future contibuteToBounty(int bountyId, int amount) { + Future contibuteToBounty(BigInt bountyId, BigInt amount) { return _sunshineClientService.contibuteToBounty(bountyId, amount); } @override - Future getBounty(int bountyId) { + Future getBounty(BigInt bountyId) { return _sunshineClientService.getBounty(bountyId); } @override - Future getSubmission(int submissionId) { + Future getSubmission(BigInt submissionId) { return _sunshineClientService.getSubmission(submissionId); } @override Future> listBountySubmissions( - int bountyId, + BigInt bountyId, ) async { - return await _sunshineClientService.listBountySubmissions(bountyId); + final list = await _sunshineClientService.listBountySubmissions(bountyId); + print('Bounty $bountyId Submissions: $list'); + return list; } @override - Future> listOpenBounties(int min) async { - return await _sunshineClientService.listOpenBounties(min); + Future> listOpenBounties(BigInt min) async { + final list = await _sunshineClientService.listOpenBounties(min); + print('Open Bounties: $list'); + return list; } @override - Future postBounty( + Future postBounty( String repoOwner, String repoName, - int issueNumber, - int amount, + BigInt issueNumber, + BigInt amount, ) { return _sunshineClientService.postBounty( repoOwner, @@ -109,12 +113,12 @@ class ProdClientService implements ClientService { } @override - Future submitForBounty( - int bountyId, + Future submitForBounty( + BigInt bountyId, String repoOwner, String repoName, - int issueNumber, - int amount, + BigInt issueNumber, + BigInt amount, ) { return _sunshineClientService.submitForBounty( bountyId, diff --git a/lib/services/client/sunshine_client_service.dart b/lib/services/client/sunshine_client_service.dart index 8fdec38..31e10dd 100644 --- a/lib/services/client/sunshine_client_service.dart +++ b/lib/services/client/sunshine_client_service.dart @@ -7,6 +7,6 @@ class SunshineClientService extends SunshineClient { SunshineClientService({PathProviderService pathProviderService}) : super( root: pathProviderService.applicationDocumentsDirectory, - chainspecPath: Uri(path: 'assets/chainspec.json'), + url: 'ws://10.0.2.2:9944', ); } diff --git a/lib/services/wallet_service.dart b/lib/services/wallet_service.dart index 5eb6432..fde221f 100644 --- a/lib/services/wallet_service.dart +++ b/lib/services/wallet_service.dart @@ -13,17 +13,17 @@ class WalletService { return _clientService.balance(); } - Future transfer(String to, int amount) { + Future transfer(String to, BigInt amount) { return _clientService.transfer(to, amount); } - Future mint() async { + Future mint() async { // Enable mint account when he tap in his balance // this just for testing ... if (kDebugMode) { return _clientService.mint(); } else { - return 0; + return BigInt.zero; } } } diff --git a/lib/ui/bounty_item.dart b/lib/ui/bounty_item.dart index 13d9b0c..146c464 100644 --- a/lib/ui/bounty_item.dart +++ b/lib/ui/bounty_item.dart @@ -142,7 +142,7 @@ class _BountyBody extends StatelessWidget { child: FittedBox( fit: BoxFit.fitWidth, child: Text( - numberFormat.format(parent.bounty.info.total), + numberFormat.format(parent.bounty.info.total.toInt()), style: TextStyle( color: const Color(0xFF25C100), fontSize: 12.ssp.toDouble(), diff --git a/lib/ui/submission_item.dart b/lib/ui/submission_item.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/ui/ui.dart b/lib/ui/ui.dart index 13772ef..0dcf2ff 100644 --- a/lib/ui/ui.dart +++ b/lib/ui/ui.dart @@ -5,5 +5,6 @@ export 'hint_text.dart'; export 'input.dart'; export 'list_cell.dart'; export 'my_app_bar.dart'; +export 'submission_item.dart'; export 'sunshine_loading.dart'; export 'sunshine_logo.dart'; diff --git a/lib/utils/github_issue_regex.dart b/lib/utils/github_issue_regex.dart index 005c108..573a68e 100644 --- a/lib/utils/github_issue_regex.dart +++ b/lib/utils/github_issue_regex.dart @@ -1,10 +1,11 @@ -final _re = RegExp(r'^https:\/\/github\.com\/(\w+)\/(\w+)\/issues\/(\d+)$'); +final _re = RegExp( + r'^https:\/\/github\.com\/([A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*)\/([A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*)\/issues\/(\d+)$'); class GithubIssueMetadata { GithubIssueMetadata({this.repo, this.owner, this.issue}); final String repo; final String owner; - final int issue; + final BigInt issue; } GithubIssueMetadata githubParseIssueUrl(String url) { @@ -15,7 +16,7 @@ GithubIssueMetadata githubParseIssueUrl(String url) { return GithubIssueMetadata( owner: groups[0], repo: groups[1], - issue: int.tryParse(groups[2]), + issue: BigInt.tryParse(groups[2]), ); } } diff --git a/native/sunshine/Cargo.toml b/native/sunshine/Cargo.toml index 25e7d85..e1335f7 100644 --- a/native/sunshine/Cargo.toml +++ b/native/sunshine/Cargo.toml @@ -12,6 +12,7 @@ crate-type = ["rlib"] [dependencies] log = "^0.4" +async-std = "=1.6.2" [dependencies.client] git = "https://github.com/sunshine-protocol/sunshine" diff --git a/native/sunshine/binding.h b/native/sunshine/binding.h index c930425..84dc117 100644 --- a/native/sunshine/binding.h +++ b/native/sunshine/binding.h @@ -8,37 +8,37 @@ * Approve a Submission using `SubmissionId` * Returns the new total amount on that bounty after this operation */ -int32_t client_bounty_approve(int64_t port, uint64_t submission_id); +int32_t client_bounty_approve(int64_t port, const char *submission_id); /** * Contribute to a bounty. * Returns the new total bounty amount */ -int32_t client_bounty_contribute(int64_t port, uint64_t bounty_id, uint64_t amount); +int32_t client_bounty_contribute(int64_t port, const char *bounty_id, const char *amount); /** * Get a bounty Information by using bounty Id - * Returns Cbor encoded `BountyInformation` as bytes + * Returns JSON encoded `BountyInformation` as string */ -int32_t client_bounty_get(int64_t port, uint64_t bounty_id); +int32_t client_bounty_get(int64_t port, const char *bounty_id); /** * Get a submission Information by using submission Id - * Returns Cbor encoded `BountySubmissionInformation` as bytes + * Returns JSON encoded `BountySubmissionInformation` as string */ -int32_t client_bounty_get_submission(int64_t port, uint64_t submission_id); +int32_t client_bounty_get_submission(int64_t port, const char *submission_id); /** * Get a list of open bounties. - * Returns a Cbor encoded list of `BountyInformation` as bytes. + * Returns a JSON encoded list of `BountyInformation` as string. */ -int32_t client_bounty_open_bounties(int64_t port, uint64_t min); +int32_t client_bounty_open_bounties(int64_t port, const char *min); /** * Get a list of open submissions on a bounty. - * Returns a Cbor encoded list of `BountySubmissionInformation` as bytes. + * Returns a JSON encoded list of `BountySubmissionInformation` as string. */ -int32_t client_bounty_open_bounty_submissions(int64_t port, uint64_t bounty_id); +int32_t client_bounty_open_bounty_submissions(int64_t port, const char *bounty_id); /** * Create a new Bounty @@ -48,18 +48,18 @@ int32_t client_bounty_post(int64_t port, const char *repo_owner, const char *repo_name, uint64_t issue_number, - uint64_t amount); + const char *amount); /** * Create a submission on a bounty * Returns the `SubmissionId` as `u64` */ int32_t client_bounty_submit(int64_t port, - uint64_t bounty_id, + const char *bounty_id, const char *repo_owner, const char *repo_name, uint64_t issue_number, - uint64_t amount); + const char *amount); /** * Try to mint the current account, this only enabled in testnet and behind a feature flag @@ -68,12 +68,14 @@ int32_t client_bounty_submit(int64_t port, int32_t client_faucet_mint(int64_t port); /** - * Setup the Sunshine Client using the provided path as the base path and with chainspec + * Setup the Sunshine Client using the provided path as the base path and with chainspec. * * ### Safety - * This assumes that the path and chain_spec is non-null c string. + * This assumes that the path non-null c string. + * chain_spec could be null. + * url could also be null. */ -int32_t client_init(int64_t port, const char *path, const char *chain_spec); +int32_t client_init(int64_t port, const char *path, const char *chain_spec, const char *url); /** * Check if the Keystore is exist and initialized. diff --git a/packages/sunshine/lib/dto.dart b/packages/sunshine/lib/dto.dart index f038cd1..c85d678 100644 --- a/packages/sunshine/lib/dto.dart +++ b/packages/sunshine/lib/dto.dart @@ -1,9 +1,6 @@ // ignore_for_file: avoid_as import 'dart:convert'; -import 'dart:typed_data'; -import 'package:cbor/cbor.dart' as cbor; -import 'package:typed_data/typed_data.dart'; class BountyInformation { BountyInformation({ @@ -12,52 +9,44 @@ class BountyInformation { this.repoName, this.issueNumber, this.depositer, - int total, + BigInt total, }) : _total = total; - factory BountyInformation.fromBytes(Uint8List bytes) { - if (bytes == null) { - return null; - } - final inst = cbor.Cbor(); - final payloadBuffer = Uint8Buffer()..addAll(bytes); - inst.decodeFromBuffer(payloadBuffer); - final data = jsonDecode(inst.decodedToJSON()); - return BountyInformation.fromJSON(data); + factory BountyInformation.fromString(String data) { + final d = json.decode(data); + return BountyInformation.fromJSON(d); } - factory BountyInformation.fromJSON(dynamic data) { return BountyInformation( - id: data['id'] as int, + id: BigInt.parse(data['id'].toString()), repoOwner: data['repo_owner'] as String, repoName: data['repo_name'] as String, - issueNumber: data['issue_number'] as int, + issueNumber: BigInt.parse(data['issue_number'].toString()), depositer: data['depositer'] as String, - total: data['total'] as int, + total: BigInt.parse(data['total'].toString()), ); } - final int id; + final BigInt id; final String repoOwner; final String repoName; - final int issueNumber; + final BigInt issueNumber; final String depositer; - int _total; - int get total => _total; + BigInt _total; + BigInt get total => _total; - static List buildList(Uint8List bytes) { - if (bytes == null) { - return []; - } - final inst = cbor.Cbor(); - final payloadBuffer = Uint8Buffer()..addAll(bytes); - inst.decodeFromBuffer(payloadBuffer); - final data = jsonDecode(inst.decodedToJSON()) as List; + static List buildList(String str) { + final data = json.decode(str) as List; return data.map((e) => BountyInformation.fromJSON(e)).toList(); } - int contibute(int amount) { + BigInt contibute(BigInt amount) { return _total += amount; } + + @override + String toString() { + return 'BountyInformation { id: $id, depositer: $depositer }'; + } } class BountySubmissionInformation { @@ -73,48 +62,39 @@ class BountySubmissionInformation { this.approved, }); - factory BountySubmissionInformation.fromBytes(Uint8List bytes) { - if (bytes == null) { - return null; - } - final inst = cbor.Cbor(); - final payloadBuffer = Uint8Buffer()..addAll(bytes); - inst.decodeFromBuffer(payloadBuffer); - final data = jsonDecode(inst.decodedToJSON()); - return BountySubmissionInformation.fromJSON(data); + factory BountySubmissionInformation.fromString(String data) { + final d = jsonDecode(data); + return BountySubmissionInformation.fromJSON(d); } factory BountySubmissionInformation.fromJSON(dynamic data) { return BountySubmissionInformation( - id: data['id'] as int, + id: BigInt.parse(data['id'].toString()), repoOwner: data['repo_owner'] as String, repoName: data['repo_name'] as String, - issueNumber: data['issue_number'] as int, - bountyId: data['bounty_id'] as int, + issueNumber: BigInt.parse(data['issue_number'].toString()), + bountyId: BigInt.parse(data['bounty_id'].toString()), submitter: data['submitter'] as String, - amount: data['amount'] as int, + amount: BigInt.parse(data['amount'].toString()), awaitingReview: data['awaiting_review'] as bool, approved: data['approved'] as bool, ); } - final int id; + final BigInt id; final String repoOwner; final String repoName; - final int issueNumber; - final int bountyId; + final BigInt issueNumber; + final BigInt bountyId; final String submitter; - final int amount; + final BigInt amount; final bool awaitingReview; final bool approved; - static List buildList(Uint8List bytes) { - if (bytes == null) { + static List buildList(String json) { + if (json.isEmpty) { return []; } - final inst = cbor.Cbor(); - final payloadBuffer = Uint8Buffer()..addAll(bytes); - inst.decodeFromBuffer(payloadBuffer); - final data = jsonDecode(inst.decodedToJSON()) as List ?? []; + final data = jsonDecode(json) as List ?? []; return data.map((e) => BountySubmissionInformation.fromJSON(e)).toList(); } } diff --git a/packages/sunshine/lib/ffi.dart b/packages/sunshine/lib/ffi.dart index 95bbd93..20e59a4 100644 --- a/packages/sunshine/lib/ffi.dart +++ b/packages/sunshine/lib/ffi.dart @@ -17,106 +17,106 @@ DynamicLibrary _open() { ///

Approve a Submission using `SubmissionId` Returns the new total amount on that bounty after this operation

int client_bounty_approve( int port, - int submission_id, + Pointer submission_id, ) { return _client_bounty_approve(port, submission_id); } final _client_bounty_approve_Dart _client_bounty_approve = _dl.lookupFunction<_client_bounty_approve_C, _client_bounty_approve_Dart>('client_bounty_approve'); typedef _client_bounty_approve_C = Int32 Function( Int64 port, - Uint64 submission_id, + Pointer submission_id, ); typedef _client_bounty_approve_Dart = int Function( int port, - int submission_id, + Pointer submission_id, ); ///

Contribute to a bounty. Returns the new total bounty amount

int client_bounty_contribute( int port, - int bounty_id, - int amount, + Pointer bounty_id, + Pointer amount, ) { return _client_bounty_contribute(port, bounty_id, amount); } final _client_bounty_contribute_Dart _client_bounty_contribute = _dl.lookupFunction<_client_bounty_contribute_C, _client_bounty_contribute_Dart>('client_bounty_contribute'); typedef _client_bounty_contribute_C = Int32 Function( Int64 port, - Uint64 bounty_id, - Uint64 amount, + Pointer bounty_id, + Pointer amount, ); typedef _client_bounty_contribute_Dart = int Function( int port, - int bounty_id, - int amount, + Pointer bounty_id, + Pointer amount, ); -///

Get a bounty Information by using bounty Id Returns Cbor encoded `BountyInformation` as bytes

+///

Get a bounty Information by using bounty Id Returns JSON encoded `BountyInformation` as string

int client_bounty_get( int port, - int bounty_id, + Pointer bounty_id, ) { return _client_bounty_get(port, bounty_id); } final _client_bounty_get_Dart _client_bounty_get = _dl.lookupFunction<_client_bounty_get_C, _client_bounty_get_Dart>('client_bounty_get'); typedef _client_bounty_get_C = Int32 Function( Int64 port, - Uint64 bounty_id, + Pointer bounty_id, ); typedef _client_bounty_get_Dart = int Function( int port, - int bounty_id, + Pointer bounty_id, ); -///

Get a submission Information by using submission Id Returns Cbor encoded `BountySubmissionInformation` as bytes

+///

Get a submission Information by using submission Id Returns JSON encoded `BountySubmissionInformation` as string

int client_bounty_get_submission( int port, - int submission_id, + Pointer submission_id, ) { return _client_bounty_get_submission(port, submission_id); } final _client_bounty_get_submission_Dart _client_bounty_get_submission = _dl.lookupFunction<_client_bounty_get_submission_C, _client_bounty_get_submission_Dart>('client_bounty_get_submission'); typedef _client_bounty_get_submission_C = Int32 Function( Int64 port, - Uint64 submission_id, + Pointer submission_id, ); typedef _client_bounty_get_submission_Dart = int Function( int port, - int submission_id, + Pointer submission_id, ); -///

Get a list of open bounties. Returns a Cbor encoded list of `BountyInformation` as bytes.

+///

Get a list of open bounties. Returns a JSON encoded list of `BountyInformation` as string.

int client_bounty_open_bounties( int port, - int min, + Pointer min, ) { return _client_bounty_open_bounties(port, min); } final _client_bounty_open_bounties_Dart _client_bounty_open_bounties = _dl.lookupFunction<_client_bounty_open_bounties_C, _client_bounty_open_bounties_Dart>('client_bounty_open_bounties'); typedef _client_bounty_open_bounties_C = Int32 Function( Int64 port, - Uint64 min, + Pointer min, ); typedef _client_bounty_open_bounties_Dart = int Function( int port, - int min, + Pointer min, ); -///

Get a list of open submissions on a bounty. Returns a Cbor encoded list of `BountySubmissionInformation` as bytes.

+///

Get a list of open submissions on a bounty. Returns a JSON encoded list of `BountySubmissionInformation` as string.

int client_bounty_open_bounty_submissions( int port, - int bounty_id, + Pointer bounty_id, ) { return _client_bounty_open_bounty_submissions(port, bounty_id); } final _client_bounty_open_bounty_submissions_Dart _client_bounty_open_bounty_submissions = _dl.lookupFunction<_client_bounty_open_bounty_submissions_C, _client_bounty_open_bounty_submissions_Dart>('client_bounty_open_bounty_submissions'); typedef _client_bounty_open_bounty_submissions_C = Int32 Function( Int64 port, - Uint64 bounty_id, + Pointer bounty_id, ); typedef _client_bounty_open_bounty_submissions_Dart = int Function( int port, - int bounty_id, + Pointer bounty_id, ); ///

Create a new Bounty Returns the `BountyId` as `u64`

@@ -125,7 +125,7 @@ int client_bounty_post( Pointer repo_owner, Pointer repo_name, int issue_number, - int amount, + Pointer amount, ) { return _client_bounty_post(port, repo_owner, repo_name, issue_number, amount); } @@ -135,43 +135,43 @@ typedef _client_bounty_post_C = Int32 Function( Pointer repo_owner, Pointer repo_name, Uint64 issue_number, - Uint64 amount, + Pointer amount, ); typedef _client_bounty_post_Dart = int Function( int port, Pointer repo_owner, Pointer repo_name, int issue_number, - int amount, + Pointer amount, ); ///

Create a submission on a bounty Returns the `SubmissionId` as `u64`

int client_bounty_submit( int port, - int bounty_id, + Pointer bounty_id, Pointer repo_owner, Pointer repo_name, int issue_number, - int amount, + Pointer amount, ) { return _client_bounty_submit(port, bounty_id, repo_owner, repo_name, issue_number, amount); } final _client_bounty_submit_Dart _client_bounty_submit = _dl.lookupFunction<_client_bounty_submit_C, _client_bounty_submit_Dart>('client_bounty_submit'); typedef _client_bounty_submit_C = Int32 Function( Int64 port, - Uint64 bounty_id, + Pointer bounty_id, Pointer repo_owner, Pointer repo_name, Uint64 issue_number, - Uint64 amount, + Pointer amount, ); typedef _client_bounty_submit_Dart = int Function( int port, - int bounty_id, + Pointer bounty_id, Pointer repo_owner, Pointer repo_name, int issue_number, - int amount, + Pointer amount, ); ///

Try to mint the current account, this only enabled in testnet and behind a feature flag returned the minted amount or null if there is any errors

@@ -188,24 +188,27 @@ typedef _client_faucet_mint_Dart = int Function( int port, ); -///

Setup the Sunshine Client using the provided path as the base path and with chainspec

### Safety This assumes that the path and chain_spec is non-null c string.

+///

Setup the Sunshine Client using the provided path as the base path and with chainspec.

### Safety This assumes that the path non-null c string. chain_spec could be null. url could also be null.

int client_init( int port, Pointer path, Pointer chain_spec, + Pointer url, ) { - return _client_init(port, path, chain_spec); + return _client_init(port, path, chain_spec, url); } final _client_init_Dart _client_init = _dl.lookupFunction<_client_init_C, _client_init_Dart>('client_init'); typedef _client_init_C = Int32 Function( Int64 port, Pointer path, Pointer chain_spec, + Pointer url, ); typedef _client_init_Dart = int Function( int port, Pointer path, Pointer chain_spec, + Pointer url, ); ///

Check if the Keystore is exist and initialized.

this is useful if you want to check if there is an already created account or not.

diff --git a/packages/sunshine/lib/sunshine_client.dart b/packages/sunshine/lib/sunshine_client.dart index 6a20a80..b345f88 100644 --- a/packages/sunshine/lib/sunshine_client.dart +++ b/packages/sunshine/lib/sunshine_client.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'dart:ffi'; import 'dart:io'; -import 'dart:typed_data'; import 'package:ffi/ffi.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:meta/meta.dart'; import 'package:isolate/ports.dart'; @@ -14,16 +14,20 @@ import 'constants.dart' as ffi; import 'ffi.dart' as ffi; class SunshineClient { - SunshineClient({@required Directory root, @required Uri chainspecPath}) - : _root = root, - _chainspecPath = chainspecPath { + SunshineClient({ + @required Directory root, + Uri chainspecPath, + String url, + }) : _root = root, + _chainspecPath = chainspecPath, + _url = url { ffi.store_dart_post_cobject(NativeApi.postCObject); FrustyLogger.init(ffi.dl); - FrustyLogger.addListener(print); } final Directory _root; final Uri _chainspecPath; + final String _url; bool _started = false; Future get ready => startUpClient(); @@ -32,11 +36,19 @@ class SunshineClient { if (_started) { return true; } - final path = Utf8.toUtf8(_root.path); - final chainspecPath = Utf8.toUtf8(await _getChainspecPath()); + FrustyLogger.addListener(print); + final spec = _chainspecPath != null + ? (await _getChainspecPath()).toUtf8Pointer() + : nullptr; + final rpcUrl = _url != null ? _url.toUtf8Pointer() : nullptr; final completer = Completer(); final port = singleCompletePort(completer); - final result = ffi.client_init(port.nativePort, path, chainspecPath); + final result = ffi.client_init( + port.nativePort, + _root.path.toUtf8Pointer(), + spec, + rpcUrl, + ); if (result == ffi.ok) { return _clientInitOkay(completer.future); } else if (result == ffi.alreadyInit) { @@ -49,179 +61,163 @@ class SunshineClient { Future hasKey() { final completer = Completer(); final port = singleCompletePort(completer); - final result = ffi.client_key_exists(port.nativePort); - assert(result == ffi.ok); + ffi.client_key_exists(port.nativePort); return completer.future; } Future uid() { final completer = Completer(); final port = singleCompletePort(completer); - final result = ffi.client_key_uid(port.nativePort); - assert(result == ffi.ok); + ffi.client_key_uid(port.nativePort); return completer.future; } Future lockKey() { final completer = Completer(); final port = singleCompletePort(completer); - final result = ffi.client_key_lock(port.nativePort); - assert(result == ffi.ok); + ffi.client_key_lock(port.nativePort); return completer.future; } Future unlockKey(String password) { final completer = Completer(); final port = singleCompletePort(completer); - final pass = Utf8.toUtf8(password); - final result = ffi.client_key_unlock(port.nativePort, pass); - assert(result == ffi.ok); + ffi.client_key_unlock(port.nativePort, password.toUtf8Pointer()); return completer.future; } Future setKey(String password, {String suri, String paperKey}) { final completer = Completer(); final port = singleCompletePort(completer); - final s = suri != null ? Utf8.toUtf8(suri) : nullptr; - final pass = Utf8.toUtf8(password); - final phrase = paperKey != null ? Utf8.toUtf8(paperKey) : nullptr; - final result = ffi.client_key_set(port.nativePort, pass, s, phrase); - assert(result == ffi.ok); + final s = suri != null ? suri.toUtf8Pointer() : nullptr; + final phrase = paperKey != null ? paperKey.toUtf8Pointer() : nullptr; + ffi.client_key_set(port.nativePort, password.toUtf8Pointer(), s, phrase); return completer.future; } - Future balance(String identifier) { + Future balance(String identifier) { final completer = Completer(); final port = singleCompletePort(completer); - final id = identifier != null ? Utf8.toUtf8(identifier) : nullptr; - final result = ffi.client_wallet_balance(port.nativePort, id); - assert(result == ffi.ok); - return completer.future.then(int.parse); + final id = identifier != null ? identifier.toUtf8Pointer() : nullptr; + ffi.client_wallet_balance(port.nativePort, id); + return completer.future.then(BigInt.parse); } - Future transfer(String identifier, int amount) { + Future transfer(String identifier, BigInt amount) { final completer = Completer(); final port = singleCompletePort(completer); - final id = Utf8.toUtf8(identifier); - final result = ffi.client_wallet_transfer(port.nativePort, id, amount); - assert(result == ffi.ok); + ffi.client_wallet_transfer( + port.nativePort, + identifier.toUtf8Pointer(), + amount.toInt(), + ); return completer.future; } - Future mint() { + Future mint() { final completer = Completer(); final port = singleCompletePort(completer); - final result = ffi.client_faucet_mint(port.nativePort); - assert(result == ffi.ok); - return completer.future.then(int.parse); + ffi.client_faucet_mint(port.nativePort); + return completer.future.then(BigInt.parse); } - Future getBounty(int bountyId) { - final completer = Completer(); + Future getBounty(BigInt bountyId) { + final completer = Completer(); final port = singleCompletePort(completer); - final result = ffi.client_bounty_get(port.nativePort, bountyId); - assert(result == ffi.ok); - return completer.future.then((bytes) => BountyInformation.fromBytes(bytes)); + ffi.client_bounty_get(port.nativePort, bountyId.toUtf8Pointer()); + return completer.future.then( + (s) => BountyInformation.fromString(s), + ); } - Future getSubmission(int submissionId) { - final completer = Completer(); + Future getSubmission(BigInt submissionId) { + final completer = Completer(); final port = singleCompletePort(completer); - final result = ffi.client_bounty_get_submission( + ffi.client_bounty_get_submission( port.nativePort, - submissionId, + submissionId.toUtf8Pointer(), ); - assert(result == ffi.ok); return completer.future.then( - (bytes) => BountySubmissionInformation.fromBytes(bytes), + (s) => BountySubmissionInformation.fromString(s), ); } - Future> listOpenBounties(int min) { - final completer = Completer(); + Future> listOpenBounties(BigInt min) { + final completer = Completer(); final port = singleCompletePort(completer); - final result = ffi.client_bounty_open_bounties( + ffi.client_bounty_open_bounties( port.nativePort, - min, + min.toUtf8Pointer(), ); - assert(result == ffi.ok); return completer.future.then(BountyInformation.buildList); } Future> listBountySubmissions( - int bountyId, + BigInt bountyId, ) { - final completer = Completer(); + final completer = Completer(); final port = singleCompletePort(completer); - final result = ffi.client_bounty_open_bounty_submissions( + ffi.client_bounty_open_bounty_submissions( port.nativePort, - bountyId, + bountyId.toUtf8Pointer(), ); - assert(result == ffi.ok); return completer.future.then(BountySubmissionInformation.buildList); } - Future postBounty( + Future postBounty( String repoOwner, String repoName, - int issueNumber, - int amount, + BigInt issueNumber, + BigInt amount, ) { - final completer = Completer(); + final completer = Completer(); final port = singleCompletePort(completer); - final owner = Utf8.toUtf8(repoOwner); - final name = Utf8.toUtf8(repoName); - final result = ffi.client_bounty_post( + ffi.client_bounty_post( port.nativePort, - owner, - name, - issueNumber, - amount, + repoOwner.toUtf8Pointer(), + repoName.toUtf8Pointer(), + issueNumber.toInt(), + amount.toUtf8Pointer(), ); - assert(result == ffi.ok); return completer.future; } - Future submitForBounty( - int bountyId, + Future submitForBounty( + BigInt bountyId, String repoOwner, String repoName, - int issueNumber, - int amount, + BigInt issueNumber, + BigInt amount, ) { - final completer = Completer(); + print('Submit for bounty id: $bountyId'); + final completer = Completer(); final port = singleCompletePort(completer); - final owner = Utf8.toUtf8(repoOwner); - final name = Utf8.toUtf8(repoName); - final result = ffi.client_bounty_submit( + ffi.client_bounty_submit( port.nativePort, - bountyId, - owner, - name, - issueNumber, - amount, + bountyId.toUtf8Pointer(), + repoOwner.toUtf8Pointer(), + repoName.toUtf8Pointer(), + issueNumber.toInt(), + amount.toUtf8Pointer(), ); - assert(result == ffi.ok); return completer.future; } - Future approveBounty(int submissionId) { + Future approveBounty(BigInt submissionId) { final completer = Completer(); final port = singleCompletePort(completer); - final result = ffi.client_bounty_approve(port.nativePort, submissionId); - assert(result == ffi.ok); + ffi.client_bounty_approve(port.nativePort, submissionId.toUtf8Pointer()); return completer.future; } - Future contibuteToBounty(int bountyId, int amount) { + Future contibuteToBounty(BigInt bountyId, BigInt amount) { final completer = Completer(); final port = singleCompletePort(completer); - final result = ffi.client_bounty_contribute( + ffi.client_bounty_contribute( port.nativePort, - bountyId, - amount, + bountyId.toUtf8Pointer(), + amount.toUtf8Pointer(), ); - assert(result == ffi.ok); return completer.future; } @@ -239,6 +235,7 @@ class SunshineClient { return res == ffi.ok; } + // ignore: unused_element Future _getChainspecPath() async { final path = '${_root.path}/chainspec.josn'; final exists = File(path).existsSync(); @@ -251,3 +248,15 @@ class SunshineClient { } } } + +extension BigIntUtf8Pointer on BigInt { + Pointer toUtf8Pointer() { + return Utf8.toUtf8(toString()); + } +} + +extension StringUtf8Pointer on String { + Pointer toUtf8Pointer() { + return Utf8.toUtf8(this); + } +} diff --git a/packages/sunshine/pubspec.lock b/packages/sunshine/pubspec.lock index 79d0479..d2a0c59 100644 --- a/packages/sunshine/pubspec.lock +++ b/packages/sunshine/pubspec.lock @@ -15,13 +15,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.0" - cbor: - dependency: "direct main" - description: - name: cbor - url: "https://pub.dartlang.org" - source: hosted - version: "3.2.0" characters: dependency: transitive description: @@ -50,13 +43,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.14.13" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.1" fake_async: dependency: transitive description: diff --git a/packages/sunshine/pubspec.yaml b/packages/sunshine/pubspec.yaml index 6751042..c9f57e4 100644 --- a/packages/sunshine/pubspec.yaml +++ b/packages/sunshine/pubspec.yaml @@ -13,7 +13,6 @@ dependencies: sdk: flutter ffi: isolate: - cbor: ^3.2.0 frusty_logger: git: https://github.com/sunshine-protocol/frusty-logger.git dev_dependencies: diff --git a/pubspec.yaml b/pubspec.yaml index d83fe1e..c42a4a8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,7 +40,7 @@ flutter: uses-material-design: true assets: - assets/svg/ - - assets/chainspec.json + # - assets/chainspec.json flutter_icons: android: true