mirror of
				https://git.wownero.com/wownero/wownero.git
				synced 2024-08-15 01:03:23 +00:00 
			
		
		
		
	Merge pull request #66 from mikezackles/master
Add get_bulk_payments rpc call
This commit is contained in:
		
						commit
						04c46fd46a
					
				
					 5 changed files with 81 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -574,11 +574,14 @@ void wallet2::get_transfers(wallet2::transfer_container& incoming_transfers) con
 | 
			
		|||
  incoming_transfers = m_transfers;
 | 
			
		||||
}
 | 
			
		||||
//----------------------------------------------------------------------------------------------------
 | 
			
		||||
void wallet2::get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments) const
 | 
			
		||||
void wallet2::get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height) const
 | 
			
		||||
{
 | 
			
		||||
  auto range = m_payments.equal_range(payment_id);
 | 
			
		||||
  std::for_each(range.first, range.second, [&payments](const payment_container::value_type& x) {
 | 
			
		||||
    payments.push_back(x.second);
 | 
			
		||||
  std::for_each(range.first, range.second, [&payments, &min_height](const payment_container::value_type& x) {
 | 
			
		||||
    if (min_height < x.second.m_block_height)
 | 
			
		||||
    {
 | 
			
		||||
      payments.push_back(x.second);
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
//----------------------------------------------------------------------------------------------------
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -143,7 +143,7 @@ namespace tools
 | 
			
		|||
    std::vector<pending_tx> create_transactions(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, const uint64_t fee, const std::vector<uint8_t> extra);
 | 
			
		||||
    bool check_connection();
 | 
			
		||||
    void get_transfers(wallet2::transfer_container& incoming_transfers) const;
 | 
			
		||||
    void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments) const;
 | 
			
		||||
    void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height = 0) const;
 | 
			
		||||
    uint64_t get_blockchain_current_height() const { return m_local_bc_height; }
 | 
			
		||||
    template <class t_archive>
 | 
			
		||||
    inline void serialize(t_archive &a, const unsigned int ver)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -268,9 +268,10 @@ namespace tools
 | 
			
		|||
    res.payments.clear();
 | 
			
		||||
    std::list<wallet2::payment_details> payment_list;
 | 
			
		||||
    m_wallet.get_payments(payment_id, payment_list);
 | 
			
		||||
    for (auto payment : payment_list)
 | 
			
		||||
    for (auto & payment : payment_list)
 | 
			
		||||
    {
 | 
			
		||||
      wallet_rpc::payment_details rpc_payment;
 | 
			
		||||
      rpc_payment.payment_id   = req.payment_id;
 | 
			
		||||
      rpc_payment.tx_hash      = epee::string_tools::pod_to_hex(payment.m_tx_hash);
 | 
			
		||||
      rpc_payment.amount       = payment.m_amount;
 | 
			
		||||
      rpc_payment.block_height = payment.m_block_height;
 | 
			
		||||
| 
						 | 
				
			
			@ -281,6 +282,51 @@ namespace tools
 | 
			
		|||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
  //------------------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
  bool wallet_rpc_server::on_get_bulk_payments(const wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS::request& req, wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx)
 | 
			
		||||
  {
 | 
			
		||||
    res.payments.clear();
 | 
			
		||||
 | 
			
		||||
    for (auto & payment_id_str : req.payment_ids)
 | 
			
		||||
    {
 | 
			
		||||
      crypto::hash payment_id;
 | 
			
		||||
      cryptonote::blobdata payment_id_blob;
 | 
			
		||||
 | 
			
		||||
      // TODO - should the whole thing fail because of one bad id?
 | 
			
		||||
 | 
			
		||||
      if(!epee::string_tools::parse_hexstr_to_binbuff(payment_id_str, payment_id_blob))
 | 
			
		||||
      {
 | 
			
		||||
        er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
 | 
			
		||||
        er.message = "Payment ID has invalid format: " + payment_id_str;
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if(sizeof(payment_id) != payment_id_blob.size())
 | 
			
		||||
      {
 | 
			
		||||
        er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
 | 
			
		||||
        er.message = "Payment ID has invalid size: " + payment_id_str;
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      payment_id = *reinterpret_cast<const crypto::hash*>(payment_id_blob.data());
 | 
			
		||||
 | 
			
		||||
      std::list<wallet2::payment_details> payment_list;
 | 
			
		||||
      m_wallet.get_payments(payment_id, payment_list, req.min_block_height);
 | 
			
		||||
 | 
			
		||||
      for (auto & payment : payment_list)
 | 
			
		||||
      {
 | 
			
		||||
        wallet_rpc::payment_details rpc_payment;
 | 
			
		||||
        rpc_payment.payment_id   = payment_id_str;
 | 
			
		||||
        rpc_payment.tx_hash      = epee::string_tools::pod_to_hex(payment.m_tx_hash);
 | 
			
		||||
        rpc_payment.amount       = payment.m_amount;
 | 
			
		||||
        rpc_payment.block_height = payment.m_block_height;
 | 
			
		||||
        rpc_payment.unlock_time  = payment.m_unlock_time;
 | 
			
		||||
        res.payments.push_back(std::move(rpc_payment));
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
  //------------------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
  bool wallet_rpc_server::on_incoming_transfers(const wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS::request& req, wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS::response& res, epee::json_rpc::error& er, connection_context& cntx)
 | 
			
		||||
  {
 | 
			
		||||
    if(req.transfer_type.compare("all") != 0 && req.transfer_type.compare("available") != 0 && req.transfer_type.compare("unavailable") != 0)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,6 +41,7 @@ namespace tools
 | 
			
		|||
        MAP_JON_RPC_WE("transfer_split",     on_transfer_split,     wallet_rpc::COMMAND_RPC_TRANSFER_SPLIT)
 | 
			
		||||
        MAP_JON_RPC_WE("store",              on_store,              wallet_rpc::COMMAND_RPC_STORE)
 | 
			
		||||
        MAP_JON_RPC_WE("get_payments",       on_get_payments,       wallet_rpc::COMMAND_RPC_GET_PAYMENTS)
 | 
			
		||||
        MAP_JON_RPC_WE("get_bulk_payments",  on_get_bulk_payments,  wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS)
 | 
			
		||||
        MAP_JON_RPC_WE("incoming_transfers", on_incoming_transfers, wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS)
 | 
			
		||||
      END_JSON_RPC_MAP()
 | 
			
		||||
    END_URI_MAP2()
 | 
			
		||||
| 
						 | 
				
			
			@ -53,6 +54,7 @@ namespace tools
 | 
			
		|||
      bool on_transfer_split(const wallet_rpc::COMMAND_RPC_TRANSFER_SPLIT::request& req, wallet_rpc::COMMAND_RPC_TRANSFER_SPLIT::response& res, epee::json_rpc::error& er, connection_context& cntx);
 | 
			
		||||
      bool on_store(const wallet_rpc::COMMAND_RPC_STORE::request& req, wallet_rpc::COMMAND_RPC_STORE::response& res, epee::json_rpc::error& er, connection_context& cntx);
 | 
			
		||||
      bool on_get_payments(const wallet_rpc::COMMAND_RPC_GET_PAYMENTS::request& req, wallet_rpc::COMMAND_RPC_GET_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx);
 | 
			
		||||
      bool on_get_bulk_payments(const wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS::request& req, wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS::response& res, epee::json_rpc::error& er, connection_context& cntx);
 | 
			
		||||
      bool on_incoming_transfers(const wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS::request& req, wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS::response& res, epee::json_rpc::error& er, connection_context& cntx);
 | 
			
		||||
 | 
			
		||||
      bool handle_command_line(const boost::program_options::variables_map& vm);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -137,12 +137,14 @@ namespace wallet_rpc
 | 
			
		|||
 | 
			
		||||
  struct payment_details
 | 
			
		||||
  {
 | 
			
		||||
    std::string payment_id;
 | 
			
		||||
    std::string tx_hash;
 | 
			
		||||
    uint64_t amount;
 | 
			
		||||
    uint64_t block_height;
 | 
			
		||||
    uint64_t unlock_time;
 | 
			
		||||
 | 
			
		||||
    BEGIN_KV_SERIALIZE_MAP()
 | 
			
		||||
      KV_SERIALIZE(payment_id)
 | 
			
		||||
      KV_SERIALIZE(tx_hash)
 | 
			
		||||
      KV_SERIALIZE(amount)
 | 
			
		||||
      KV_SERIALIZE(block_height)
 | 
			
		||||
| 
						 | 
				
			
			@ -170,6 +172,29 @@ namespace wallet_rpc
 | 
			
		|||
      END_KV_SERIALIZE_MAP()
 | 
			
		||||
    };
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  struct COMMAND_RPC_GET_BULK_PAYMENTS
 | 
			
		||||
  {
 | 
			
		||||
    struct request
 | 
			
		||||
    {
 | 
			
		||||
      std::vector<std::string> payment_ids;
 | 
			
		||||
      uint64_t min_block_height;
 | 
			
		||||
 | 
			
		||||
      BEGIN_KV_SERIALIZE_MAP()
 | 
			
		||||
        KV_SERIALIZE(payment_ids)
 | 
			
		||||
        KV_SERIALIZE(min_block_height)
 | 
			
		||||
      END_KV_SERIALIZE_MAP()
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    struct response
 | 
			
		||||
    {
 | 
			
		||||
      std::list<payment_details> payments;
 | 
			
		||||
 | 
			
		||||
      BEGIN_KV_SERIALIZE_MAP()
 | 
			
		||||
        KV_SERIALIZE(payments)
 | 
			
		||||
      END_KV_SERIALIZE_MAP()
 | 
			
		||||
    };
 | 
			
		||||
  };
 | 
			
		||||
  
 | 
			
		||||
  struct transfer_details
 | 
			
		||||
  {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue