38 const std::string& address) {
39 if (txs_.find(
id) == txs_.end()) {
40 LOG(ERROR) <<
"no utxo:" << id;
41 return absl::InvalidArgumentError(
"id invalid.");
44 UTXO* utxo = txs_[id].get();
46 if (utxo->out_size() <= out_idx) {
47 LOG(ERROR) <<
" idx not found:" << out_idx <<
" id:" << id;
48 return absl::InvalidArgumentError(
"id invalid.");
51 if (utxo->out(out_idx).spent()) {
52 LOG(ERROR) <<
" value has been spent:" <<
id <<
" idx:" << out_idx;
53 return absl::InvalidArgumentError(
"id has been spent.");
56 if (utxo->out(out_idx).address() != address) {
57 LOG(ERROR) <<
" address not match:" << address
58 <<
" utxo addr:" << utxo->out(out_idx).address();
59 return absl::InvalidArgumentError(
"address invalid.");
61 return utxo->out(out_idx);
65 const std::string& address) {
66 if (txs_.find(
id) == txs_.end()) {
67 LOG(ERROR) <<
"no utxo:" << id;
71 UTXO* utxo = txs_[id].get();
73 if (utxo->out_size() <= out_idx) {
74 LOG(ERROR) <<
" idx not found:" << out_idx <<
" id:" << id;
78 if (utxo->out(out_idx).spent()) {
79 LOG(ERROR) <<
" value has been spent:" <<
id <<
" idx:" << out_idx;
82 if (utxo->out(out_idx).address() != address) {
83 LOG(ERROR) <<
" address not match:" << address
84 <<
" utxo addr:" << utxo->out(out_idx).address();
87 return utxo->out(out_idx).value();
109 int64_t max_id = ((--txs_.end())->first);
113 std::vector<UTXO> resp;
114 for (
int i = 0; i < num; ++i) {
115 if (txs_.find(end_idx - i) == txs_.end()) {
118 resp.push_back(*txs_[end_idx - i]);
119 resp.back().set_transaction_id(end_idx - i);
122 std::reverse(resp.begin(), resp.end());