Loading...
Searching...
No Matches
tx_mempool.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include "absl/status/statusor.h"
23#include "proto/utxo/utxo.pb.h"
24
25namespace resdb {
26namespace utxo {
27
28class TxMempool {
29 public:
30 TxMempool();
31 ~TxMempool();
32
33 // Add a new utxo and return the transaction id.
34 int64_t AddUTXO(const UTXO& utxo);
35
36 // get the transfer value from a transantion "id" in its output[out_idx].
37 // if the address not match or the transaction does not exist, return -1
38 int64_t GetUTXOOutValue(int64_t id, int out_idx, const std::string& address);
39
40 absl::StatusOr<UTXOOut> GetUTXO(int64_t id, int out_idx,
41 const std::string& address);
42
43 // Mark the output of a trans has been spent.
44 // Return the out value.
45 int64_t MarkSpend(int64_t id, int out_idx, const std::string& address);
46
47 std::vector<UTXO> GetUTXO(int64_t end_idx, int num);
48
49 private:
50 std::map<int64_t, std::unique_ptr<UTXO> > txs_;
51 std::atomic<int64_t> id_;
52};
53
54} // namespace utxo
55} // namespace resdb
int64_t AddUTXO(const UTXO &utxo)
int64_t GetUTXOOutValue(int64_t id, int out_idx, const std::string &address)
int64_t MarkSpend(int64_t id, int out_idx, const std::string &address)
absl::StatusOr< UTXOOut > GetUTXO(int64_t id, int out_idx, const std::string &address)