Skip to content

Commit

Permalink
Add rest of commands to ModelBuilder.
Browse files Browse the repository at this point in the history
Signed-off-by: luckychess <[email protected]>
  • Loading branch information
luckychess authored and lebdron committed Dec 19, 2017
1 parent fef726b commit 7c37020
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 5 deletions.
54 changes: 53 additions & 1 deletion shared_model/bindings/model_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,65 @@ namespace shared_model {
return ModelBuilder(builder_.txCounter(tx_counter));
}

ModelBuilder ModelBuilder::addAssetQuantity(
ModelBuilder ModelBuilder::createdTime(
interface::types::TimestampType created_time) {
return ModelBuilder(builder_.createdTime(created_time));
}

ModelBuilder ModelBuilder::assetQuantity(
const interface::types::AccountIdType &account_id,
const interface::types::AssetIdType &asset_id,
const std::string &amount) {
return ModelBuilder(builder_.assetQuantity(account_id, asset_id, amount));
}

ModelBuilder ModelBuilder::addPeer(
const interface::types::AddressType &address,
const interface::types::PubkeyType &peer_key) {
return ModelBuilder(builder_.addPeer(address, peer_key));
}

ModelBuilder ModelBuilder::addSignatory(
const interface::types::AddressType &account_id,
const interface::types::PubkeyType &public_key) {
return ModelBuilder(builder_.addSignatory(account_id, public_key));
}

ModelBuilder ModelBuilder::removeSignatory(
const interface::types::AddressType &account_id,
const interface::types::PubkeyType &public_key) {
return ModelBuilder(builder_.removeSignatory(account_id, public_key));
}

ModelBuilder ModelBuilder::createAccount(
const std::string &account_name,
const interface::types::AddressType &domain_id,
const interface::types::PubkeyType &main_pubkey) {
return ModelBuilder(
builder_.createAccount(account_name, domain_id, main_pubkey));
}

ModelBuilder ModelBuilder::createDomain(
const interface::types::AddressType &domain_id,
const interface::types::RoleIdType &default_role) {
return ModelBuilder(builder_.createDomain(domain_id, default_role));
}

ModelBuilder ModelBuilder::setAccountQuorum(
const interface::types::AddressType &account_id, uint32_t quorum) {
return ModelBuilder(builder_.setAccountQuorum(account_id, quorum));
}

ModelBuilder ModelBuilder::transferAsset(
const interface::types::AccountIdType &src_account_id,
const interface::types::AccountIdType &dest_account_id,
const interface::types::AssetIdType &asset_id,
const std::string &description,
const std::string &amount) {
return ModelBuilder(builder_.transferAsset(
src_account_id, dest_account_id, asset_id, description, amount));
}

proto::UnsignedWrapper<proto::Transaction> ModelBuilder::build() {
return builder_.build();
}
Expand Down
86 changes: 84 additions & 2 deletions shared_model/bindings/model_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "builders/protobuf/transaction.hpp"
#include "builders/protobuf/unsigned_proto.hpp"
#include "cryptography/public_key.hpp"

namespace shared_model {
namespace bindings {
Expand Down Expand Up @@ -51,18 +52,99 @@ namespace shared_model {
*/
ModelBuilder txCounter(uint64_t tx_counter);

/**
* Sets time of creation
* @param created_time - time of creation
* @return builder with created_time field appended
*/
ModelBuilder createdTime(interface::types::TimestampType created_time);

/**
* Adds given quantity of given asset to account
* @param account_id - account id
* @param asset_id - asset id
* @param amount - amount of asset to add
* @return builder with added given quantity of given asset for account
* @return builder with asset quantity command appended
*/
ModelBuilder addAssetQuantity(
ModelBuilder assetQuantity(
const interface::types::AccountIdType &account_id,
const interface::types::AssetIdType &asset_id,
const std::string &amount);

/**
* Adds new peer into ledger
* @param address - peer address
* @param peer_key - peer public key
* @return builder with added peer command appended
*/
ModelBuilder addPeer(const interface::types::AddressType &address,
const crypto::PublicKey &peer_key);

/**
* Adds new signatory
* @param account_id - id of signatory's account
* @param public_key - public key of signatory
* @return builder with added signatory command appended
*/
ModelBuilder addSignatory(const interface::types::AddressType &account_id,
const crypto::PublicKey &public_key);

/**
* Removes signatory
* @param account_id - id of signatory's account to remove
* @param public_key - public key of signatory
* @return builder with removed signatory command appended
*/
ModelBuilder removeSignatory(
const interface::types::AddressType &account_id,
const crypto::PublicKey &public_key);

/**
* Creates new account
* @param account_name - name of account to create
* @param domain_id - id of domain where account will be created
* @param main_pubkey - main public key of account
* @return builder with new account command appended
*/
ModelBuilder createAccount(const std::string &account_name,
const interface::types::AddressType &domain_id,
const crypto::PublicKey &main_pubkey);

/**
* Creates new domain
* @param domain_id - domain name to create
* @param default_role - default role name
* @return builder with new domain command appended
*/
ModelBuilder createDomain(
const interface::types::AddressType &domain_id,
const interface::types::RoleIdType &default_role);

/**
* Sets account quorum
* @param account_id - id of account to set quorum
* @param quorum - quorum amount
* @return builder with set account quorum command appended
*/
ModelBuilder setAccountQuorum(
const interface::types::AddressType &account_id, uint32_t quorum);

/**
* Transfers asset from one account to another
* @param src_account_id - source account id
* @param dest_account_id - destination account id
* @param asset_id - asset id
* @param description - description message which user can set
* @param amount - amount of asset to transfer
* @return buidler with transfer asset command appended
*/
ModelBuilder transferAsset(
const interface::types::AccountIdType &src_account_id,
const interface::types::AccountIdType &dest_account_id,
const interface::types::AssetIdType &asset_id,
const std::string &description,
const std::string &amount);

/**
* Builds result with all appended fields
* @return wrapper on unsigned transaction
Expand Down
4 changes: 2 additions & 2 deletions shared_model/builders/protobuf/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ namespace shared_model {

iroha::protocol::Transaction transaction_;

public:
template <int Sp>
TemplateTransactionBuilder(const TemplateTransactionBuilder<Sp> &o)
: transaction_(o.transaction_) {}

public:
TemplateTransactionBuilder() = default;

NextBuilder<CreatorAccountId> creatorAccountId(
Expand All @@ -67,7 +67,7 @@ namespace shared_model {
return *this;
}

NextBuilder<CreatedTime> createdTime(uint64_t created_time) {
NextBuilder<CreatedTime> createdTime(interface::types::TimestampType created_time) {
transaction_.mutable_payload()->set_created_time(created_time);
return *this;
}
Expand Down

0 comments on commit 7c37020

Please sign in to comment.