mirror of https://github.com/oxen-io/oxen-core.git
Add RPC calls for updating lns tx
This commit is contained in:
parent
c2b0d37c60
commit
1197ae9635
|
@ -870,7 +870,19 @@ bool validate_mapping_type(std::string const &type, lns::mapping_type *mapping_t
|
|||
}
|
||||
catch (std::exception const &)
|
||||
{
|
||||
if (reason) *reason = "Failed to convert lns mapping (was not proper integer, or not one of the recognised: \"session\"), string was=" + type;
|
||||
if (reason)
|
||||
{
|
||||
*reason = "Failed to convert lns mapping (was not proper integer, or not one of the recognised: \"session\"), string was";
|
||||
if (type.empty())
|
||||
{
|
||||
*reason += " empty.";
|
||||
}
|
||||
else
|
||||
{
|
||||
*reason += "=";
|
||||
*reason += type;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6678,14 +6678,14 @@ bool simple_wallet::update_lns_mapping(const std::vector<std::string>& args)
|
|||
std::vector<tools::wallet2::pending_tx> ptx_vector;
|
||||
try
|
||||
{
|
||||
ptx_vector = m_wallet->update_lns_mapping_tx(lns::mapping_type::session,
|
||||
name,
|
||||
*value,
|
||||
signature,
|
||||
&reason,
|
||||
priority,
|
||||
m_current_subaddress_account,
|
||||
subaddr_indices);
|
||||
ptx_vector = m_wallet->create_update_lns_mapping_tx(lns::mapping_type::session,
|
||||
name,
|
||||
*value,
|
||||
signature,
|
||||
&reason,
|
||||
priority,
|
||||
m_current_subaddress_account,
|
||||
subaddr_indices);
|
||||
if (ptx_vector.empty())
|
||||
{
|
||||
tools::fail_msg_writer() << reason;
|
||||
|
|
|
@ -8669,14 +8669,14 @@ std::vector<wallet2::pending_tx> wallet2::create_buy_lns_mapping_tx(std::string
|
|||
return result;
|
||||
}
|
||||
|
||||
std::vector<wallet2::pending_tx> wallet2::update_lns_mapping_tx(lns::mapping_type type,
|
||||
std::string const &name,
|
||||
std::string const &value,
|
||||
std::string const *signature,
|
||||
std::string *reason,
|
||||
uint32_t priority,
|
||||
uint32_t account_index,
|
||||
std::set<uint32_t> subaddr_indices)
|
||||
std::vector<wallet2::pending_tx> wallet2::create_update_lns_mapping_tx(lns::mapping_type type,
|
||||
std::string const &name,
|
||||
std::string const &value,
|
||||
std::string const *signature,
|
||||
std::string *reason,
|
||||
uint32_t priority,
|
||||
uint32_t account_index,
|
||||
std::set<uint32_t> subaddr_indices)
|
||||
{
|
||||
crypto::hash prev_txid;
|
||||
lns::lns_value value_blob;
|
||||
|
@ -8725,6 +8725,23 @@ std::vector<wallet2::pending_tx> wallet2::update_lns_mapping_tx(lns::mapping_typ
|
|||
return result;
|
||||
}
|
||||
|
||||
std::vector<wallet2::pending_tx> wallet2::create_update_lns_mapping_tx(std::string const &type,
|
||||
std::string const &name,
|
||||
std::string const &value,
|
||||
std::string const *signature,
|
||||
std::string *reason,
|
||||
uint32_t priority,
|
||||
uint32_t account_index,
|
||||
std::set<uint32_t> subaddr_indices)
|
||||
{
|
||||
lns::mapping_type mapping_type = lns::mapping_type::session;
|
||||
if (!lns::validate_mapping_type(type, &mapping_type, reason))
|
||||
return {};
|
||||
|
||||
std::vector<wallet2::pending_tx> result = create_update_lns_mapping_tx(mapping_type, name, value, signature, reason, priority, account_index, subaddr_indices);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool wallet2::lock_keys_file()
|
||||
{
|
||||
if (m_keys_file_locker)
|
||||
|
|
|
@ -1552,7 +1552,11 @@ private:
|
|||
request_stake_unlock_result can_request_stake_unlock(const crypto::public_key &sn_key);
|
||||
std::vector<wallet2::pending_tx> create_buy_lns_mapping_tx(lns::mapping_type type, std::string const &owner, std::string const &name, std::string const &value, std::string *reason, uint32_t priority = 0, uint32_t account_index = 0, std::set<uint32_t> subaddr_indices = {});
|
||||
std::vector<wallet2::pending_tx> create_buy_lns_mapping_tx(std::string const &type, std::string const &owner, std::string const &name, std::string const &value, std::string *reason, uint32_t priority = 0, uint32_t account_index = 0, std::set<uint32_t> subaddr_indices = {});
|
||||
std::vector<wallet2::pending_tx> update_lns_mapping_tx(lns::mapping_type type, std::string const &name, std::string const &value, std::string const *signature, std::string *reason, uint32_t priority = 0, uint32_t account_index = 0, std::set<uint32_t> subaddr_indices = {});
|
||||
|
||||
// signature: (Optional) If set, use the signature given, otherwise by default derive the signature from the wallet spend key as an ed25519 key.
|
||||
// The signature is derived from the hash of the previous txid blob and previous value blob of the mapping. By default this is signed using the wallet's spend key as an ed25519 keypair.
|
||||
std::vector<wallet2::pending_tx> create_update_lns_mapping_tx(lns::mapping_type type, std::string const &name, std::string const &value, std::string const *signature, std::string *reason, uint32_t priority = 0, uint32_t account_index = 0, std::set<uint32_t> subaddr_indices = {});
|
||||
std::vector<wallet2::pending_tx> create_update_lns_mapping_tx(std::string const &type, std::string const &name, std::string const &value, std::string const *signature, std::string *reason, uint32_t priority = 0, uint32_t account_index = 0, std::set<uint32_t> subaddr_indices = {});
|
||||
|
||||
void freeze(size_t idx);
|
||||
void thaw(size_t idx);
|
||||
|
|
|
@ -4309,6 +4309,51 @@ namespace tools
|
|||
res.tx_metadata,
|
||||
er);
|
||||
}
|
||||
|
||||
bool wallet_rpc_server::on_update_lns_mapping(const wallet_rpc::COMMAND_RPC_UPDATE_LNS_MAPPING::request &req, wallet_rpc::COMMAND_RPC_UPDATE_LNS_MAPPING::response &res, epee::json_rpc::error &er, const connection_context *ctx)
|
||||
{
|
||||
if (!m_wallet) return not_open(er);
|
||||
if (m_restricted)
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_DENIED;
|
||||
er.message = "Updating lns mappings is unavailable in restricted mode.";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string reason;
|
||||
std::vector<wallet2::pending_tx> ptx_vector =
|
||||
m_wallet->create_update_lns_mapping_tx(req.type,
|
||||
req.name,
|
||||
req.value,
|
||||
req.signature.empty() ? nullptr : &req.signature,
|
||||
&reason,
|
||||
req.priority,
|
||||
req.account_index,
|
||||
req.subaddr_indices);
|
||||
|
||||
if (ptx_vector.empty())
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_TX_NOT_POSSIBLE;
|
||||
er.message = "Failed to create LNS update transaction: " + reason;
|
||||
return false;
|
||||
}
|
||||
|
||||
return fill_response(ptx_vector,
|
||||
req.get_tx_key,
|
||||
res.tx_key,
|
||||
res.amount,
|
||||
res.fee,
|
||||
res.multisig_txset,
|
||||
res.unsigned_txset,
|
||||
req.do_not_relay,
|
||||
false /*blink*/,
|
||||
res.tx_hash,
|
||||
req.get_tx_hex,
|
||||
res.tx_blob,
|
||||
req.get_tx_metadata,
|
||||
res.tx_metadata,
|
||||
er);
|
||||
}
|
||||
}
|
||||
|
||||
class t_daemon
|
||||
|
|
|
@ -165,6 +165,7 @@ namespace tools
|
|||
MAP_JON_RPC_WE("can_request_stake_unlock", on_can_request_stake_unlock, wallet_rpc::COMMAND_RPC_CAN_REQUEST_STAKE_UNLOCK)
|
||||
MAP_JON_RPC_WE("request_stake_unlock", on_request_stake_unlock, wallet_rpc::COMMAND_RPC_REQUEST_STAKE_UNLOCK)
|
||||
MAP_JON_RPC_WE("buy_lns_mapping", on_buy_lns_mapping, wallet_rpc::COMMAND_RPC_BUY_LNS_MAPPING)
|
||||
MAP_JON_RPC_WE("update_lns_mapping", on_update_lns_mapping, wallet_rpc::COMMAND_RPC_UPDATE_LNS_MAPPING)
|
||||
END_JSON_RPC_MAP()
|
||||
END_URI_MAP2()
|
||||
|
||||
|
@ -256,6 +257,7 @@ namespace tools
|
|||
bool on_can_request_stake_unlock(const wallet_rpc::COMMAND_RPC_CAN_REQUEST_STAKE_UNLOCK::request& req, wallet_rpc::COMMAND_RPC_CAN_REQUEST_STAKE_UNLOCK::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
|
||||
bool on_request_stake_unlock(const wallet_rpc::COMMAND_RPC_REQUEST_STAKE_UNLOCK::request& req, wallet_rpc::COMMAND_RPC_REQUEST_STAKE_UNLOCK::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
|
||||
bool on_buy_lns_mapping(const wallet_rpc::COMMAND_RPC_BUY_LNS_MAPPING::request& req, wallet_rpc::COMMAND_RPC_BUY_LNS_MAPPING::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
|
||||
bool on_update_lns_mapping(const wallet_rpc::COMMAND_RPC_UPDATE_LNS_MAPPING::request& req, wallet_rpc::COMMAND_RPC_UPDATE_LNS_MAPPING::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
|
||||
|
||||
//json rpc v2
|
||||
bool on_query_key(const wallet_rpc::COMMAND_RPC_QUERY_KEY::request& req, wallet_rpc::COMMAND_RPC_QUERY_KEY::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
|
||||
|
|
|
@ -2877,7 +2877,7 @@ namespace wallet_rpc
|
|||
|
||||
uint32_t account_index; // (Optional) Transfer from this account index. (Defaults to 0)
|
||||
std::set<uint32_t> subaddr_indices; // (Optional) Transfer from this set of subaddresses. (Defaults to 0)
|
||||
uint32_t priority; // Set a priority for the transaction. Accepted Values are: 0-3 for: default, unimportant, normal, elevated, priority.
|
||||
uint32_t priority; // Set a priority for the transaction. Accepted values are: or 0-4 for: default, unimportant, normal, elevated, priority.
|
||||
bool get_tx_key; // (Optional) Return the transaction key after sending.
|
||||
bool do_not_relay; // (Optional) If true, the newly created transaction will not be relayed to the loki network. (Defaults to false)
|
||||
bool get_tx_hex; // Return the transaction as hex string after sending (Defaults to false)
|
||||
|
@ -2924,5 +2924,66 @@ namespace wallet_rpc
|
|||
typedef epee::misc_utils::struct_init<response_t> response;
|
||||
};
|
||||
|
||||
LOKI_RPC_DOC_INTROSPECT
|
||||
// Update the underlying value in the name->value mapping via Loki Name Service.
|
||||
struct COMMAND_RPC_UPDATE_LNS_MAPPING
|
||||
{
|
||||
struct request_t
|
||||
{
|
||||
std::string type; // The mapping type, currently only "session" is supported.
|
||||
std::string name; // The name to update via Loki Name Service
|
||||
std::string value; // The new value that the name maps to via Loki Name Service, (i.e. For session: display name -> session public key).
|
||||
std::string signature; // (Optional): Signature derived from the hash of the previous txid blob and previous value blob of the mapping. By default this is signed using the wallet's spend key as an ed25519 keypair, if signature is empty.
|
||||
|
||||
uint32_t account_index; // (Optional) Transfer from this account index. (Defaults to 0)
|
||||
std::set<uint32_t> subaddr_indices; // (Optional) Transfer from this set of subaddresses. (Defaults to 0)
|
||||
uint32_t priority; // Set a priority for the transaction. Accepted values are: 0-4 for: default, unimportant, normal, elevated, priority.
|
||||
bool get_tx_key; // (Optional) Return the transaction key after sending.
|
||||
bool do_not_relay; // (Optional) If true, the newly created transaction will not be relayed to the loki network. (Defaults to false)
|
||||
bool get_tx_hex; // Return the transaction as hex string after sending (Defaults to false)
|
||||
bool get_tx_metadata; // Return the metadata needed to relay the transaction. (Defaults to false)
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE (type);
|
||||
KV_SERIALIZE (name);
|
||||
KV_SERIALIZE (value);
|
||||
KV_SERIALIZE_OPT(signature, std::string(""));
|
||||
|
||||
KV_SERIALIZE_OPT(account_index, (uint32_t)0);
|
||||
KV_SERIALIZE_OPT(subaddr_indices, {});
|
||||
KV_SERIALIZE_OPT(priority, (uint32_t)0);
|
||||
KV_SERIALIZE (get_tx_key)
|
||||
KV_SERIALIZE_OPT(do_not_relay, false)
|
||||
KV_SERIALIZE_OPT(get_tx_hex, false)
|
||||
KV_SERIALIZE_OPT(get_tx_metadata, false)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
typedef epee::misc_utils::struct_init<request_t> request;
|
||||
|
||||
struct response_t
|
||||
{
|
||||
std::string tx_hash; // Publically searchable transaction hash.
|
||||
std::string tx_key; // Transaction key if `get_tx_key` is `true`, otherwise, blank string.
|
||||
uint64_t amount; // Amount transferred for the transaction in atomic units.
|
||||
uint64_t fee; // Value in atomic units of the fee charged for the tx.
|
||||
std::string tx_blob; // Raw transaction represented as hex string, if get_tx_hex is true.
|
||||
std::string tx_metadata; // Set of transaction metadata needed to relay this transfer later, if `get_tx_metadata` is `true`.
|
||||
std::string multisig_txset; // Set of multisig transactions in the process of being signed (empty for non-multisig).
|
||||
std::string unsigned_txset; // Set of unsigned tx for cold-signing purposes.
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(tx_hash)
|
||||
KV_SERIALIZE(tx_key)
|
||||
KV_SERIALIZE(amount)
|
||||
KV_SERIALIZE(fee)
|
||||
KV_SERIALIZE(tx_blob)
|
||||
KV_SERIALIZE(tx_metadata)
|
||||
KV_SERIALIZE(multisig_txset)
|
||||
KV_SERIALIZE(unsigned_txset)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
typedef epee::misc_utils::struct_init<response_t> response;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue