Wallet API
This commit is contained in:
parent
d0c72f7cf7
commit
0d79d5d0ee
6 changed files with 240 additions and 7 deletions
|
|
@ -301,7 +301,7 @@ struct get_impacted_account_visitor
|
|||
_impacted.insert( op.to );
|
||||
}
|
||||
void operator()( const nft_approve_operation& op ) {
|
||||
_impacted.insert( op.owner );
|
||||
_impacted.insert( op.operator_ );
|
||||
_impacted.insert( op.approved );
|
||||
}
|
||||
void operator()( const nft_set_approval_for_all_operation& op ) {
|
||||
|
|
|
|||
|
|
@ -37,12 +37,12 @@ namespace graphene { namespace chain {
|
|||
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
|
||||
asset fee;
|
||||
|
||||
account_id_type owner;
|
||||
account_id_type operator_;
|
||||
|
||||
account_id_type approved;
|
||||
nft_id_type token_id;
|
||||
|
||||
account_id_type fee_payer()const { return owner; }
|
||||
account_id_type fee_payer()const { return operator_; }
|
||||
};
|
||||
|
||||
struct nft_set_approval_for_all_operation : public base_operation
|
||||
|
|
@ -67,6 +67,6 @@ FC_REFLECT( graphene::chain::nft_set_approval_for_all_operation::fee_parameters_
|
|||
|
||||
FC_REFLECT( graphene::chain::nft_create_operation, (fee) (owner) (approved) (approved_operators) (metadata) )
|
||||
FC_REFLECT( graphene::chain::nft_safe_transfer_from_operation, (fee) (operator_) (from) (to) (token_id) (data) )
|
||||
FC_REFLECT( graphene::chain::nft_approve_operation, (fee) (owner) (approved) (token_id) )
|
||||
FC_REFLECT( graphene::chain::nft_approve_operation, (fee) (operator_) (approved) (token_id) )
|
||||
FC_REFLECT( graphene::chain::nft_set_approval_for_all_operation, (fee) (owner) (operator_) (approved) )
|
||||
|
||||
|
|
|
|||
|
|
@ -72,13 +72,13 @@ void_result nft_approve_evaluator::do_evaluate( const nft_approve_operation& op
|
|||
auto itr_nft = idx_nft.find(op.token_id);
|
||||
FC_ASSERT( itr_nft != idx_nft.end(), "NFT does not exists" );
|
||||
|
||||
auto itr_owner = idx_acc.find(op.owner);
|
||||
auto itr_owner = idx_acc.find(op.operator_);
|
||||
FC_ASSERT( itr_owner != idx_acc.end(), "Owner account does not exists" );
|
||||
|
||||
auto itr_approved = idx_acc.find(op.approved);
|
||||
FC_ASSERT( itr_approved != idx_acc.end(), "Approved account does not exists" );
|
||||
|
||||
auto itr_approved_op = std::find(itr_nft->approved_operators.begin(), itr_nft->approved_operators.end(), op.owner);
|
||||
auto itr_approved_op = std::find(itr_nft->approved_operators.begin(), itr_nft->approved_operators.end(), op.operator_);
|
||||
FC_ASSERT( (itr_nft->owner == itr_owner->id) || (itr_approved_op != itr_nft->approved_operators.end()), "Sender is not NFT owner or approved operator" );
|
||||
|
||||
return void_result();
|
||||
|
|
|
|||
|
|
@ -1895,6 +1895,110 @@ class wallet_api
|
|||
bool is_gpos,
|
||||
bool broadcast);
|
||||
|
||||
/////////
|
||||
// NFT //
|
||||
/////////
|
||||
/**
|
||||
* @brief Creates NFT
|
||||
* @param owner_account_id_or_name Owner account ID or name
|
||||
* @param approved_account_id_or_name Approved account ID or name
|
||||
* @param approved_operators_id_or_name Approved operator IDs or names
|
||||
* @param metadata NFT metadata
|
||||
* @param broadcast true to broadcast transaction to the network
|
||||
* @return Signed transaction transfering the funds
|
||||
*/
|
||||
signed_transaction nft_create(string owner_account_id_or_name,
|
||||
string approved_account_id_or_name,
|
||||
string metadata,
|
||||
bool broadcast);
|
||||
|
||||
/**
|
||||
* @brief Returns the number of NFT owned by account
|
||||
* @param owner_account_id_or_name Owner account ID or name
|
||||
* @return Number of NFTs owned by account
|
||||
*/
|
||||
uint64_t nft_get_balance(string owner_account_id_or_name) const;
|
||||
|
||||
/**
|
||||
* @brief Returns the NFT owner
|
||||
* @param token_id NFT ID
|
||||
* @return NFT owner account ID
|
||||
*/
|
||||
optional<account_id_type> nft_owner_of(const nft_id_type token_id) const;
|
||||
|
||||
/**
|
||||
* @brief Transfers NFT safely
|
||||
* @param operator_account_id_or_name Operators account ID or name
|
||||
* @param from_account_id_or_name Senders account ID or name
|
||||
* @param to_account_id_or_name Receivers account ID or name
|
||||
* @param token_id NFT ID
|
||||
* @param data Non mandatory data
|
||||
* @param broadcast true to broadcast transaction to the network
|
||||
* @return Signed transaction transfering NFT
|
||||
*/
|
||||
signed_transaction nft_safe_transfer_from(string operator_account_id_or_name,
|
||||
string from_account_id_or_name,
|
||||
string to_account_id_or_name,
|
||||
nft_id_type token_id,
|
||||
string data,
|
||||
bool broadcast);
|
||||
|
||||
/**
|
||||
* @brief Transfers NFT
|
||||
* @param operator_account_id_or_name Operators account ID or name
|
||||
* @param from_account_id_or_name Senders account ID or name
|
||||
* @param to_account_id_or_name Receivers account ID or name
|
||||
* @param token_id NFT ID
|
||||
* @param broadcast true to broadcast transaction to the network
|
||||
* @return Signed transaction transfering NFT
|
||||
*/
|
||||
signed_transaction nft_transfer_from(string operator_account_id_or_name,
|
||||
string from_account_id_or_name,
|
||||
string to_account_id_or_name,
|
||||
nft_id_type token_id,
|
||||
bool broadcast);
|
||||
|
||||
/**
|
||||
* @brief Sets approved account for NFT
|
||||
* @param operator_account_id_or_name Operators account ID or name
|
||||
* @param approved_account_id_or_name Senders account ID or name
|
||||
* @param token_id NFT ID
|
||||
* @param broadcast true to broadcast transaction to the network
|
||||
* @return Signed transaction setting approving account for NFT
|
||||
*/
|
||||
signed_transaction nft_approve(string operator_account_id_or_name,
|
||||
string approved_account_id_or_name,
|
||||
nft_id_type token_id,
|
||||
bool broadcast);
|
||||
|
||||
/**
|
||||
* @brief Sets approval for all NFT owned by owner
|
||||
* @param owner_account_id_or_name Owner account ID or name
|
||||
* @param operator_account_id_or_name Operator account ID or name
|
||||
* @param approved true if approved
|
||||
* @param broadcast true to broadcast transaction to the network
|
||||
* @return Signed transaction setting approvals for all NFT owned by owner
|
||||
*/
|
||||
signed_transaction nft_set_approval_for_all(string owner_account_id_or_name,
|
||||
string operator_account_id_or_name,
|
||||
bool approved,
|
||||
bool broadcast);
|
||||
|
||||
/**
|
||||
* @brief Returns the NFT approved account ID
|
||||
* @param token_id NFT ID
|
||||
* @return NFT approved account ID
|
||||
*/
|
||||
optional<account_id_type> nft_get_approved(const nft_id_type token_id) const;
|
||||
|
||||
/**
|
||||
* @brief Returns operator approved state for all NFT owned by owner
|
||||
* @param owner NFT owner account ID
|
||||
* @param token_id NFT ID
|
||||
* @return True if operator is approved for all NFT owned by owner, else False
|
||||
*/
|
||||
bool nft_is_approved_for_all(string owner_account_id_or_name, string operator_account_id_or_name) const;
|
||||
|
||||
void dbg_make_uia(string creator, string symbol);
|
||||
void dbg_make_mia(string creator, string symbol);
|
||||
void dbg_push_blocks( std::string src_filename, uint32_t count );
|
||||
|
|
@ -2145,6 +2249,14 @@ FC_API( graphene::wallet::wallet_api,
|
|||
(tournament_leave)
|
||||
(rps_throw)
|
||||
(create_vesting_balance)
|
||||
(nft_get_balance)
|
||||
(nft_owner_of)
|
||||
(nft_safe_transfer_from)
|
||||
(nft_transfer_from)
|
||||
(nft_approve)
|
||||
(nft_set_approval_for_all)
|
||||
(nft_get_approved)
|
||||
(nft_is_approved_for_all)
|
||||
(get_upcoming_tournaments)
|
||||
(get_tournaments)
|
||||
(get_tournaments_by_state)
|
||||
|
|
|
|||
|
|
@ -6157,6 +6157,127 @@ signed_transaction wallet_api::create_vesting_balance(string owner,
|
|||
return my->sign_transaction( trx, broadcast );
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::nft_create(string owner_account_id_or_name,
|
||||
string approved_account_id_or_name,
|
||||
string metadata,
|
||||
bool broadcast)
|
||||
{
|
||||
account_object owner_account = my->get_account(owner_account_id_or_name);
|
||||
account_object approved_account = my->get_account(approved_account_id_or_name);
|
||||
|
||||
nft_create_operation op;
|
||||
op.owner = owner_account.id;
|
||||
op.approved = approved_account.id;
|
||||
op.metadata = metadata;
|
||||
|
||||
signed_transaction trx;
|
||||
trx.operations.push_back(op);
|
||||
my->set_operation_fees( trx, my->_remote_db->get_global_properties().parameters.current_fees );
|
||||
trx.validate();
|
||||
|
||||
return my->sign_transaction( trx, broadcast );
|
||||
}
|
||||
|
||||
uint64_t wallet_api::nft_get_balance(string owner_account_id_or_name) const
|
||||
{
|
||||
account_object owner_account = my->get_account(owner_account_id_or_name);
|
||||
return my->_remote_db->nft_get_balance(owner_account.id);
|
||||
}
|
||||
|
||||
optional<account_id_type> wallet_api::nft_owner_of(const nft_id_type token_id) const
|
||||
{
|
||||
return my->_remote_db->nft_owner_of(token_id);
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::nft_safe_transfer_from(string operator_account_id_or_name,
|
||||
string from_account_id_or_name,
|
||||
string to_account_id_or_name,
|
||||
nft_id_type token_id,
|
||||
string data,
|
||||
bool broadcast)
|
||||
{
|
||||
account_object operator_account = my->get_account(operator_account_id_or_name);
|
||||
account_object from_account = my->get_account(from_account_id_or_name);
|
||||
account_object to_account = my->get_account(to_account_id_or_name);
|
||||
|
||||
nft_safe_transfer_from_operation op;
|
||||
op.operator_ = operator_account.id;
|
||||
op.from = from_account.id;
|
||||
op.to = to_account.id;
|
||||
op.token_id = token_id;
|
||||
op.data = data;
|
||||
|
||||
signed_transaction trx;
|
||||
trx.operations.push_back(op);
|
||||
my->set_operation_fees( trx, my->_remote_db->get_global_properties().parameters.current_fees );
|
||||
trx.validate();
|
||||
|
||||
return my->sign_transaction( trx, broadcast );
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::nft_transfer_from(string operator_account_id_or_name,
|
||||
string from_account_id_or_name,
|
||||
string to_account_id_or_name,
|
||||
nft_id_type token_id,
|
||||
bool broadcast)
|
||||
{
|
||||
return nft_safe_transfer_from(operator_account_id_or_name, from_account_id_or_name, to_account_id_or_name, token_id, "", broadcast);
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::nft_approve(string operator_account_id_or_name,
|
||||
string approved_account_id_or_name,
|
||||
nft_id_type token_id,
|
||||
bool broadcast)
|
||||
{
|
||||
account_object operator_account = my->get_account(operator_account_id_or_name);
|
||||
account_object approved_account = my->get_account(approved_account_id_or_name);
|
||||
|
||||
nft_approve_operation op;
|
||||
op.operator_ = operator_account.id;
|
||||
op.approved = approved_account.id;
|
||||
op.token_id = token_id;
|
||||
|
||||
signed_transaction trx;
|
||||
trx.operations.push_back(op);
|
||||
my->set_operation_fees( trx, my->_remote_db->get_global_properties().parameters.current_fees );
|
||||
trx.validate();
|
||||
|
||||
return my->sign_transaction( trx, broadcast );
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::nft_set_approval_for_all(string owner_account_id_or_name,
|
||||
string operator_account_id_or_name,
|
||||
bool approved,
|
||||
bool broadcast)
|
||||
{
|
||||
account_object owner_account = my->get_account(owner_account_id_or_name);
|
||||
account_object operator_account = my->get_account(operator_account_id_or_name);
|
||||
|
||||
nft_set_approval_for_all_operation op;
|
||||
op.owner = owner_account.id;
|
||||
op.operator_ = operator_account.id;
|
||||
op.approved = approved;
|
||||
|
||||
signed_transaction trx;
|
||||
trx.operations.push_back(op);
|
||||
my->set_operation_fees( trx, my->_remote_db->get_global_properties().parameters.current_fees );
|
||||
trx.validate();
|
||||
|
||||
return my->sign_transaction( trx, broadcast );
|
||||
}
|
||||
|
||||
optional<account_id_type> wallet_api::nft_get_approved(const nft_id_type token_id) const
|
||||
{
|
||||
return my->_remote_db->nft_get_approved(token_id);
|
||||
}
|
||||
|
||||
bool wallet_api::nft_is_approved_for_all(string owner_account_id_or_name, string operator_account_id_or_name) const
|
||||
{
|
||||
account_object owner_account = my->get_account(owner_account_id_or_name);
|
||||
account_object operator_account = my->get_account(operator_account_id_or_name);
|
||||
return my->_remote_db->nft_is_approved_for_all(owner_account.id, operator_account.id);
|
||||
}
|
||||
|
||||
// default ctor necessary for FC_REFLECT
|
||||
signed_block_with_info::signed_block_with_info()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ BOOST_AUTO_TEST_CASE( nft_approve_operation_test ) {
|
|||
BOOST_TEST_MESSAGE("Send nft_approve_operation");
|
||||
|
||||
nft_approve_operation op;
|
||||
op.owner = alice_id;
|
||||
op.operator_ = alice_id;
|
||||
op.approved = operator3_id;
|
||||
op.token_id = nft_id_type(0);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue