Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions lib/ain-ocean/src/indexer/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ pub fn index_transaction(ctx: &BlockContext, tx: Transaction, idx: usize) -> Res
SERVICES.transaction.by_id.put(&tx_id, &trx)?;
// Indexing transaction vin
for (vin_idx, vin) in tx.input.iter().enumerate() {
let vout_bytes = vin.previous_output.vout.to_be_bytes();
let trx_vin = TransactionVin {
id: format!("{}-{}", tx_id, vin_idx),
id: format!(
Comment thread
nagarajm22 marked this conversation as resolved.
Outdated
"{}-{}-{}",
tx_id,
vin.previous_output.txid,
hex::encode(vout_bytes)
),
txid: tx_id,
coinbase: vin.script_sig.to_string(),
vout: TransactionVinVout {
Expand All @@ -66,6 +72,7 @@ pub fn index_transaction(ctx: &BlockContext, tx: Transaction, idx: usize) -> Res
}
// Index transaction vout
for (vout_idx, vout) in tx.output.iter().enumerate() {
let vout_index = vout_idx.to_be_bytes();
let trx_vout = TransactionVout {
id: format!("{}-{}", tx_id, vout_idx),
txid: tx_id.to_string(),
Expand All @@ -77,15 +84,31 @@ pub fn index_transaction(ctx: &BlockContext, tx: Transaction, idx: usize) -> Res
r#type: "pubkey".to_string(),
},
};
SERVICES.transaction.vout_by_id.put(&tx_id, &trx_vout)?;
// .put(&format!("{}-{}", tx_id, vout_idx), &trx_vout)?; //need
SERVICES
.transaction
.vout_by_id
.put(&format!("{}-{}", tx_id, hex::encode(vout_index)), &trx_vout)?;
}

Ok(())
}

pub fn invalidate_transaction(ctx: &BlockContext, tx: Txid, idx: usize) -> Result<()> {
pub fn invalidate_transaction(tx_id: Txid) -> Result<()> {
debug!("[invalidate_transaction] Invalidating...");
SERVICES.transaction.by_id.delete(&tx)?;
SERVICES.transaction.by_id.delete(&tx_id)?;
Ok(())
}

//txid: txid + vout.txid + (vin.previous_output.vout 4 bytes encoded hex)
pub fn invalidate_transaction_vin(tx_id: String) -> Result<()> {
debug!("[invalidate_transaction] Invalidating...");
SERVICES.transaction.vout_by_id.delete(&tx_id)?;
Ok(())
}

//txid which is string type (txid + encoded (vout_idx)
pub fn invalidate_transaction_vout(tx_id: String) -> Result<()> {
debug!("[invalidate_transaction] Invalidating...");
SERVICES.transaction.vout_by_id.delete(&tx_id)?;
Ok(())
}
6 changes: 4 additions & 2 deletions lib/ain-ocean/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ pub use api::ocean_router;
use error::OceanError;
pub use indexer::{
index_block, invalidate_block,
transaction::{index_transaction, invalidate_transaction},
transaction::{
index_transaction, invalidate_transaction, invalidate_transaction_vin,
invalidate_transaction_vout,
},
tx_result, BlockV2Info,
};
use model::TransactionVin;
use repository::{
AuctionHistoryByHeightRepository, AuctionHistoryRepository, BlockByHeightRepository,
BlockRepository, MasternodeByHeightRepository, MasternodeRepository, MasternodeStatsRepository,
Expand Down
2 changes: 1 addition & 1 deletion lib/ain-ocean/src/repository/transaction_vout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
};

#[derive(Repository)]
#[repository(K = "Txid", V = "TransactionVout")]
#[repository(K = "String", V = "TransactionVout")]
pub struct TransactionVoutRepository {
pub store: Arc<OceanStore>,
col: LedgerColumn<columns::TransactionVout>,
Expand Down
2 changes: 1 addition & 1 deletion lib/ain-ocean/src/storage/columns/transaction_vout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl ColumnName for TransactionVout {
}

impl Column for TransactionVout {
type Index = Txid;
type Index = String;
}

impl TypedColumn for TransactionVout {
Expand Down
6 changes: 4 additions & 2 deletions src/dfi/consensus/poolpairs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ Res CPoolPairsConsensus::operator()(const CPoolSwapMessage &obj) const {
const auto &tx = txCtx.GetTransaction();
auto &mnview = blockCtx.GetView();

return CPoolSwap(obj, height, std::make_pair(CustomTxType::PoolSwap, tx.GetHash())).ExecuteSwap(mnview, {}, consensus);
return CPoolSwap(obj, height, std::make_pair(CustomTxType::PoolSwap, tx.GetHash()))
.ExecuteSwap(mnview, {}, consensus);
}

Res CPoolPairsConsensus::operator()(const CPoolSwapMessageV2 &obj) const {
Expand All @@ -146,7 +147,8 @@ Res CPoolPairsConsensus::operator()(const CPoolSwapMessageV2 &obj) const {
const auto &tx = txCtx.GetTransaction();
auto &mnview = blockCtx.GetView();

return CPoolSwap(obj.swapInfo, height, std::make_pair(CustomTxType::PoolSwapV2, tx.GetHash())).ExecuteSwap(mnview, obj.poolIDs, consensus);
return CPoolSwap(obj.swapInfo, height, std::make_pair(CustomTxType::PoolSwapV2, tx.GetHash()))
.ExecuteSwap(mnview, obj.poolIDs, consensus);
}

Res CPoolPairsConsensus::operator()(const CLiquidityMessage &obj) const {
Expand Down
4 changes: 2 additions & 2 deletions src/dfi/govvariables/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,8 @@ static inline void rtrim(std::string &s, unsigned char remove) {
s.erase(std::find_if(s.rbegin(), s.rend(), [&remove](unsigned char ch) { return ch != remove; }).base(), s.end());
}

const std::map<uint8_t, std::map<uint8_t, std::function<ResVal<CAttributeValue>(const std::string &)>>>
&ATTRIBUTES::parseValue() {
const std::map<uint8_t, std::map<uint8_t, std::function<ResVal<CAttributeValue>(const std::string &)>>> &
ATTRIBUTES::parseValue() {
static const std::map<uint8_t, std::map<uint8_t, std::function<ResVal<CAttributeValue>(const std::string &)>>>
parsers{
{AttributeTypes::Token,
Expand Down
4 changes: 2 additions & 2 deletions src/dfi/govvariables/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,8 @@ class ATTRIBUTES : public GovVariable, public AutoRegistrator<GovVariable, ATTRI
static const std::map<std::string, uint8_t> &allowedVaultIDs();
static const std::map<std::string, uint8_t> &allowedRulesIDs();
static const std::map<uint8_t, std::map<std::string, uint8_t>> &allowedKeys();
static const std::map<uint8_t, std::map<uint8_t, std::function<ResVal<CAttributeValue>(const std::string &)>>>
&parseValue();
static const std::map<uint8_t, std::map<uint8_t, std::function<ResVal<CAttributeValue>(const std::string &)>>> &
parseValue();

Res ProcessVariable(const std::string &key,
const std::optional<UniValue> &value,
Expand Down
5 changes: 4 additions & 1 deletion src/dfi/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,10 @@ Res CPoolSwap::ExecuteSwap(CCustomCSView &view,
if (txInfo) {
const auto &[txType, txHash] = *txInfo;
CrossBoundaryResult ffiResult;
ocean_try_set_tx_result(ffiResult, static_cast<uint8_t>(txType), txHash.GetByteArray(), static_cast<std::size_t>(reinterpret_cast<uintptr_t>(&finalSwapAmount)));
ocean_try_set_tx_result(ffiResult,
static_cast<uint8_t>(txType),
txHash.GetByteArray(),
static_cast<std::size_t>(reinterpret_cast<uintptr_t>(&finalSwapAmount)));
}

return Res::Ok();
Expand Down
4 changes: 3 additions & 1 deletion src/dfi/mn_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ class CPoolSwap {
public:
std::vector<std::pair<std::string, std::string>> errors;

CPoolSwap(const CPoolSwapMessage &obj, const uint32_t height, const std::optional<std::pair<CustomTxType, uint256>> txInfo = std::nullopt)
CPoolSwap(const CPoolSwapMessage &obj,
const uint32_t height,
const std::optional<std::pair<CustomTxType, uint256>> txInfo = std::nullopt)
: obj(obj),
height(height),
txInfo(txInfo) {}
Expand Down
9 changes: 5 additions & 4 deletions src/dfi/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <ain_rs_exports.h>
#include <chain.h>
#include <consensus/validation.h>
#include <dfi/accountshistory.h>
#include <dfi/errors.h>
#include <dfi/govvariables/attributes.h>
Expand All @@ -21,7 +22,6 @@
#include <ffi/ffiexports.h>
#include <ffi/ffihelpers.h>
#include <validation.h>
#include <consensus/validation.h>

#include <boost/asio.hpp>

Expand Down Expand Up @@ -2810,8 +2810,8 @@ Res ProcessDeFiEventFallible(const CBlock &block,
info.size_stripped = GetSerializeSize(block, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
info.weight = GetBlockWeight(block);
info.stake_modifier = pindex->stakeModifier.ToString();
info.minter = ""; // mn operator address
info.masternode = ""; // mn owner address
info.minter = ""; // mn operator address
info.masternode = ""; // mn owner address

// minter info
CKeyID minter;
Expand All @@ -2822,7 +2822,8 @@ Res ProcessDeFiEventFallible(const CBlock &block,
info.masternode = id->ToString();
auto mn = mnview.GetMasternode(*id);
if (mn) {
auto dest = mn->operatorType == 1 ? CTxDestination(PKHash(minter)) : CTxDestination(WitnessV0KeyHash(minter));
auto dest =
mn->operatorType == 1 ? CTxDestination(PKHash(minter)) : CTxDestination(WitnessV0KeyHash(minter));
info.minter = EncodeDestination(dest);
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/ffi/cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ namespace rust {
static String lossy(const char16_t *) noexcept;
static String lossy(const char16_t *, std::size_t) noexcept;

String &operator=(const String &) &noexcept;
String &operator=(String &&) &noexcept;
String &operator=(const String &) & noexcept;
String &operator=(String &&) & noexcept;

explicit operator std::string() const;

Expand Down Expand Up @@ -115,7 +115,7 @@ namespace rust {
Str(const char *);
Str(const char *, std::size_t);

Str &operator=(const Str &) &noexcept = default;
Str &operator=(const Str &) & noexcept = default;

explicit operator std::string() const;

Expand Down Expand Up @@ -163,8 +163,8 @@ namespace rust {
struct copy_assignable_if<false> {
copy_assignable_if() noexcept = default;
copy_assignable_if(const copy_assignable_if &) noexcept = default;
copy_assignable_if &operator=(const copy_assignable_if &) &noexcept = delete;
copy_assignable_if &operator=(copy_assignable_if &&) &noexcept = default;
copy_assignable_if &operator=(const copy_assignable_if &) & noexcept = delete;
copy_assignable_if &operator=(copy_assignable_if &&) & noexcept = default;
};
} // namespace detail

Expand All @@ -177,8 +177,8 @@ namespace rust {
Slice() noexcept;
Slice(T *, std::size_t count) noexcept;

Slice &operator=(const Slice<T> &) &noexcept = default;
Slice &operator=(Slice<T> &&) &noexcept = default;
Slice &operator=(const Slice<T> &) & noexcept = default;
Slice &operator=(Slice<T> &&) & noexcept = default;

T *data() const noexcept;
std::size_t size() const noexcept;
Expand Down Expand Up @@ -265,7 +265,7 @@ namespace rust {
explicit Box(const T &);
explicit Box(T &&);

Box &operator=(Box &&) &noexcept;
Box &operator=(Box &&) & noexcept;

const T *operator->() const noexcept;
const T &operator*() const noexcept;
Expand Down Expand Up @@ -310,7 +310,7 @@ namespace rust {
Vec(Vec &&) noexcept;
~Vec() noexcept;

Vec &operator=(Vec &&) &noexcept;
Vec &operator=(Vec &&) & noexcept;
Vec &operator=(const Vec &) &;

std::size_t size() const noexcept;
Expand Down Expand Up @@ -391,7 +391,7 @@ namespace rust {
~Error() noexcept override;

Error &operator=(const Error &) &;
Error &operator=(Error &&) &noexcept;
Error &operator=(Error &&) & noexcept;

const char *what() const noexcept override;

Expand Down Expand Up @@ -758,7 +758,7 @@ namespace rust {
}

template <typename T>
Box<T> &Box<T>::operator=(Box &&other) &noexcept {
Box<T> &Box<T>::operator=(Box &&other) & noexcept {
if (this->ptr) {
this->drop();
}
Expand Down Expand Up @@ -849,7 +849,7 @@ namespace rust {
}

template <typename T>
Vec<T> &Vec<T>::operator=(Vec &&other) &noexcept {
Vec<T> &Vec<T>::operator=(Vec &&other) & noexcept {
this->drop();
this->repr = other.repr;
new (&other) Vec();
Expand Down