Skip to content

Commit

Permalink
feat: blueberry ring repo
Browse files Browse the repository at this point in the history
  • Loading branch information
reasje committed Jul 26, 2024
1 parent 0ff67c7 commit 40d9220
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
77 changes: 77 additions & 0 deletions logic/lib/src/domain/repositories/wallet/blueberry_ring.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import 'dart:async';
import 'package:http/http.dart';
import 'package:mxc_logic/src/data/api/client/rest_client.dart';
import 'package:mxc_logic/mxc_logic.dart';
import 'package:mxc_logic/src/data/api/client/web3_client.dart';
import 'package:ens_dart/ens_dart.dart' as contracts;
import 'package:web3dart/crypto.dart';

import 'package:web3dart/web3dart.dart';

class BlueberryRingRepository {
BlueberryRingRepository(
this._web3Client,
) : _restClient = RestClient().client;

final DatadashClient _web3Client;
final Client _restClient;

Future<String> sendSyncTransaction(String privateKey, BlueberryRingMiner ring,
PostClaimResponseModel postClaimResponse, String memo,) async {
final cred = EthPrivateKey.fromHex(privateKey);

final doitDeviceAddress = ContractAddresses.getContractAddress(
MXCContacts.doitDevice,
_web3Client.network!.chainId,
);

final healthAddress = ContractAddresses.getContractAddress(
MXCContacts.health,
_web3Client.network!.chainId,
);

final doitDeviceContract = contracts.DoitRINGDevice(
address: doitDeviceAddress,
client: _web3Client,
chainId: _web3Client.network!.chainId,
);

final signature = await doitDeviceContract.claimInSender(
postClaimResponse.uid,
ring.sncode,
[
{
'token': healthAddress,
'amount': postClaimResponse.amount,
}
],
hexToBytes(postClaimResponse.signature),
memo,
credentials: cred,
);

return signature;
}

Future<PostClaimResponseModel> postClaim(
PostClaimRequestModel requestData) async {
print('postClaim:requestData : $requestData');
final chainId = _web3Client.network!.chainId;
final response = await _restClient.post(
Uri.parse(
Urls.getBlueberryRingDapp(chainId) + Urls.blueberryRingDappClaim,
),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: requestData.toJson(),
);

print('postClaim:response.body : ${response.body}');
print('postClaim:response.bodyBytes : ${response.bodyBytes}');
final responseData = PostClaimResponseModel.fromJson(response.body);
print('postClaim:responseData : ${responseData.toString}');
return responseData;
}
}
1 change: 1 addition & 0 deletions logic/lib/src/domain/repositories/wallet/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export 'transaction_controller.dart';
export 'tweets.dart';
export 'url_launcher.dart';
export 'ipfs.dart';
export 'blueberry_ring.dart';
4 changes: 4 additions & 0 deletions logic/lib/src/domain/repositories/web3_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class Web3Repository {
MinerRepository get minerRepository =>
MinerRepository(_web3client, epochRepository, tokenContract);

BlueberryRingRepository get blueberryRingRepository => BlueberryRingRepository(
_web3client,
);

EpochRepository get epochRepository => EpochRepository(_web3client);

LauncherRepository get launcherRepository => LauncherRepository(_web3client);
Expand Down
Empty file.

0 comments on commit 40d9220

Please sign in to comment.