Skip to content

Commit

Permalink
add runAction
Browse files Browse the repository at this point in the history
add Action factory for vote action - we use factory to create actions, and the generic runAction method to execute them
  • Loading branch information
n13 committed Sep 18, 2024
1 parent 9d72b5d commit d6d95a7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/core/network/api/actions/vote_action_factory.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:hypha_wallet/core/crypto/seeds_esr/eos_action.dart';

class Voteactionfactory {
// Vote action
// Note: Don't hard-code the dao contract since it's different on different networks
// get daoContract by calling
// final daoContract = remoteConfigService.daoContract(network: network);
//
static EOSAction voteAction(String daoContract, String voter, int proposalId, String vote) {
if (vote != 'pass' && vote != 'fail') {
throw 'vote needs to be one of pass or fail';
}
return EOSAction()
..account = daoContract
..name = 'vote'
..data = {
'voter': voter,
'proposal_id': proposalId,
'vote': vote,
};
}
}
16 changes: 16 additions & 0 deletions lib/core/network/api/eos_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:async/async.dart';
import 'package:dio/dio.dart' as dio;
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:hypha_wallet/core/crypto/eosdart/eosdart.dart';
import 'package:hypha_wallet/core/crypto/seeds_esr/eos_action.dart';
import 'package:hypha_wallet/core/crypto/seeds_esr/eos_transaction.dart';
import 'package:hypha_wallet/core/local/models/user_auth_data.dart';
import 'package:hypha_wallet/core/local/services/secure_storage_service.dart';
Expand Down Expand Up @@ -81,6 +82,21 @@ class EOSService {
return sendTransaction(user: fromUser, eosTransaction: transferTransaction);
}

/// Run a single action from signer account
Future<Result<String>> runAction({
required UserProfileData signer,
required EOSAction action,
}) async {
if (action.authorization == null) {
final auth = Authorization()
..actor = signer.accountName
..permission = 'active';
action.authorization = [auth];
}
final transferTransaction = EOSTransaction([action], signer.network);
return sendTransaction(user: signer, eosTransaction: transferTransaction);
}

Future<Result<dynamic>> deleteBlockchainAccount({
required UserProfileData user,
}) async {
Expand Down

0 comments on commit d6d95a7

Please sign in to comment.