Skip to content

Commit

Permalink
Ocean: refinements II (#3100)
Browse files Browse the repository at this point in the history
* allow empty

* cors allowmethods refined

* secondary index snafu

* should not del key

* fix oracle_price_active is not indexed

* fmt_rs

* refactor getactiveprice

* opt: rm oracle_price_aggregated key

* opt: rm oracle_price_aggregated_interval key

* opt: rm oracle_price_feed key

* opt: rm oracle_price_active key

* fmt_rs

* struct dftx derive clone

* refine <index|invalidate>_block_<start|end> flow

* pretty

* fix poolswap index_block_start

* safe add

* opt

* fix rawtx.ctrl.send validate_composite_swap_tx

* fmt_rs

* fix script_unspent_vin key

* fix api vault auction history

* fix list_vault_auction_history pagination
  • Loading branch information
canonbrother authored Oct 29, 2024
1 parent 54ea232 commit 0ca2fba
Show file tree
Hide file tree
Showing 35 changed files with 673 additions and 628 deletions.
16 changes: 8 additions & 8 deletions lib/ain-dftx/src/types/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,50 @@ use super::{
common::CompactVec,
};

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct UtxosToAccount {
pub to: CompactVec<ScriptBalances>,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct AccountToUtxos {
pub from: ScriptBuf,
pub balances: CompactVec<TokenBalanceUInt32>,
pub minting_outputs_start: VarInt,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct AccountToAccount {
pub from: ScriptBuf,
pub to: CompactVec<ScriptBalances>,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct AnyAccountsToAccounts {
pub from: CompactVec<ScriptBalances>,
pub to: CompactVec<ScriptBalances>,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct TransferDomainItem {
pub address: ScriptBuf,
pub amount: TokenBalanceVarInt,
pub domain: u8,
pub data: Vec<u8>,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct TransferDomainPair {
pub src: TransferDomainItem,
pub dst: TransferDomainItem,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct TransferDomain {
pub items: CompactVec<TransferDomainPair>,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct SetFutureSwap {
pub owner: ScriptBuf,
pub source: TokenBalanceVarInt,
Expand Down
6 changes: 3 additions & 3 deletions lib/ain-dftx/src/types/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ use bitcoin::{io, ScriptBuf, VarInt};
use super::common::CompactVec;

// CBalances
#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct TokenBalanceUInt32 {
pub token: u32,
pub amount: i64,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct ScriptBalances {
pub script: ScriptBuf,
pub balances: CompactVec<TokenBalanceUInt32>,
}

// CTokenAmount
#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct TokenBalanceVarInt {
pub token: VarInt,
pub amount: i64,
Expand Down
8 changes: 4 additions & 4 deletions lib/ain-dftx/src/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bitcoin::{
io::{self, ErrorKind},
};

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct CompactVec<T>(Vec<T>);

impl<T: Encodable + std::fmt::Debug> Encodable for CompactVec<T> {
Expand Down Expand Up @@ -46,7 +46,7 @@ impl<T> AsRef<Vec<T>> for CompactVec<T> {
}
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Maybe<T>(pub Option<T>);
impl<T: Encodable + std::fmt::Debug> Encodable for Maybe<T> {
fn consensus_encode<W: bitcoin::io::Write + ?Sized>(
Expand Down Expand Up @@ -82,7 +82,7 @@ impl<T> From<Option<T>> for Maybe<T> {
}
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct RawBytes(pub Vec<u8>);

impl Encodable for RawBytes {
Expand Down Expand Up @@ -110,7 +110,7 @@ impl Decodable for RawBytes {
/// In the rust-bitcoin library, variable-length integers are implemented as CompactSize.
/// See [issue #1016](https://github.com/rust-bitcoin/rust-bitcoin/issues/1016)
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct VarInt(pub u64);

impl Encodable for VarInt {
Expand Down
2 changes: 1 addition & 1 deletion lib/ain-dftx/src/types/evmtx.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ain_macros::ConsensusEncoding;
use bitcoin::io;

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct EvmTx {
pub raw: Vec<u8>,
}
22 changes: 11 additions & 11 deletions lib/ain-dftx/src/types/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,43 @@ use bitcoin::{
use super::common::CompactVec;
use crate::{common::RawBytes, types::common::Maybe};

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct LiqPoolSplit {
pub token_id: u32,
pub value: i64,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct LpDailyReward {
pub key: String,
pub value: i64,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct LpSplits {
pub key: String,
pub value: CompactVec<LiqPoolSplit>,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct LpUnmapped {
pub key: String,
pub value: RawBytes,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct LoanTokenSplit {
pub token_id: VarInt,
pub value: i64,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct LpLoanTokenSplits {
pub key: String,
pub value: CompactVec<LoanTokenSplit>,
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum GovernanceVar {
LpDailyReward(LpDailyReward),
LpSplits(LpSplits),
Expand Down Expand Up @@ -89,7 +89,7 @@ impl Decodable for GovernanceVar {
}
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct SetGovernance {
pub governance_vars: Vec<GovernanceVar>,
}
Expand Down Expand Up @@ -117,7 +117,7 @@ impl Decodable for SetGovernance {
}
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct SetGovernanceHeight {
pub var: GovernanceVar,
pub activation_height: u32,
Expand Down Expand Up @@ -150,7 +150,7 @@ impl Decodable for SetGovernanceHeight {
}
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct CreateProposal {
pub r#type: u8,
pub address: ScriptBuf,
Expand All @@ -162,7 +162,7 @@ pub struct CreateProposal {
pub options: u8,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct Vote {
pub proposal_id: Txid,
pub masternode_id: Txid,
Expand Down
14 changes: 7 additions & 7 deletions lib/ain-dftx/src/types/icxorderbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bitcoin::{io, ScriptBuf, Txid};

use crate::common::{CompactVec, Maybe, VarInt};

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct ICXCreateOrder {
pub order_type: u8,
pub token_id: VarInt,
Expand All @@ -15,7 +15,7 @@ pub struct ICXCreateOrder {
pub expiry: u32,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct ICXMakeOffer {
pub order_tx: Txid,
pub amount: i64,
Expand All @@ -25,15 +25,15 @@ pub struct ICXMakeOffer {
pub taker_fee: u64,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct ICXSubmitDFCHTLC {
pub offer_tx: Txid,
pub amount: i64,
pub hash: Txid,
pub timeout: u32,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct ICXSubmitEXTHTLC {
pub offer_tx: Txid,
pub amount: i64,
Expand All @@ -43,18 +43,18 @@ pub struct ICXSubmitEXTHTLC {
pub timeout: u32,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct ICXClaimDFCHTLC {
pub dfc_htlc_tx: Txid,
pub seed: Vec<u8>,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct ICXCloseOrder {
pub order_tx: Txid,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct ICXCloseOffer {
pub offer_tx: Txid,
}
20 changes: 10 additions & 10 deletions lib/ain-dftx/src/types/loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@ use bitcoin::{io, ScriptBuf, Txid, VarInt};

use super::{balance::TokenBalanceUInt32, common::CompactVec, price::CurrencyPair};

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct SetLoanScheme {
pub ratio: u32,
pub rate: i64,
pub identifier: String,
pub update: i64,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct DestroyLoanScheme {
pub identifier: String,
pub height: i64,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct SetDefaultLoanScheme {
pub identifier: String,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct SetCollateralToken {
pub token: VarInt,
pub factor: i64,
pub currency_pair: CurrencyPair,
pub activate_after_block: u32,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct SetLoanToken {
pub symbol: String,
pub name: String,
Expand All @@ -39,7 +39,7 @@ pub struct SetLoanToken {
pub interest: i64,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct UpdateLoanToken {
pub symbol: String,
pub name: String,
Expand All @@ -49,27 +49,27 @@ pub struct UpdateLoanToken {
pub token_tx: Txid,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct TakeLoan {
pub vault_id: Txid,
pub to: ScriptBuf,
pub token_amounts: CompactVec<TokenBalanceUInt32>,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct PaybackLoan {
pub vault_id: Txid,
pub from: ScriptBuf,
pub token_amounts: CompactVec<TokenBalanceUInt32>,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct TokenPayback {
pub d_token: VarInt,
pub amounts: CompactVec<TokenBalanceUInt32>,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct PaybackLoanV2 {
pub vault_id: Txid,
pub from: ScriptBuf,
Expand Down
10 changes: 5 additions & 5 deletions lib/ain-dftx/src/types/masternode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ use bitcoin::{

use super::common::{CompactVec, Maybe};

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct CreateMasternode {
pub operator_type: u8,
pub operator_pub_key_hash: PubkeyHash,
pub timelock: Maybe<u16>,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct ResignMasternode {
pub node_id: Txid,
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct UpdateMasternodeAddress {
pub r#type: u8,
pub address_pub_key_hash: Option<PubkeyHash>,
Expand Down Expand Up @@ -59,13 +59,13 @@ impl Decodable for UpdateMasternodeAddress {
}
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct UpdateMasternodeData {
pub r#type: u8,
pub address: UpdateMasternodeAddress,
}

#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
#[derive(ConsensusEncoding, Debug, PartialEq, Eq, Clone)]
pub struct UpdateMasternode {
pub node_id: Txid,
pub updates: CompactVec<UpdateMasternodeData>,
Expand Down
Loading

0 comments on commit 0ca2fba

Please sign in to comment.