96 lines
3.9 KiB
Rust
96 lines
3.9 KiB
Rust
|
|
use crate::blocks::burn::BurnTransaction;
|
||
|
|
use crate::blocks::collateral::CollateralClaimTransaction;
|
||
|
|
use crate::blocks::genesis::GenesisTransaction;
|
||
|
|
use crate::blocks::issue_token::IssueTokenTransaction;
|
||
|
|
use crate::blocks::loan_payment::ContractPaymentTransaction;
|
||
|
|
use crate::blocks::loans::LoanContractTransaction;
|
||
|
|
use crate::blocks::marketing::MarketingTransaction;
|
||
|
|
use crate::blocks::nft::CreateNftTransaction;
|
||
|
|
use crate::blocks::rewards::RewardsTransaction;
|
||
|
|
use crate::blocks::swap::SwapTransaction;
|
||
|
|
use crate::blocks::token::CreateTokenTransaction;
|
||
|
|
use crate::blocks::transfer::TransferTransaction;
|
||
|
|
use crate::blocks::vanity::VanityAddressTransaction;
|
||
|
|
use crate::Serialize;
|
||
|
|
|
||
|
|
// Transaction type bytes are the canonical IDs used in blocks, mempool
|
||
|
|
// routing, and verification dispatch.
|
||
|
|
pub const GENESIS_TYPE: u8 = 0;
|
||
|
|
pub const REWARDS_TYPE: u8 = 1;
|
||
|
|
pub const TRANSFER_TYPE: u8 = 2;
|
||
|
|
pub const CREATE_TOKEN_TYPE: u8 = 3;
|
||
|
|
pub const CREATE_NFT_TYPE: u8 = 4;
|
||
|
|
pub const MARKETING_TYPE: u8 = 5;
|
||
|
|
pub const SWAP_TYPE: u8 = 6;
|
||
|
|
pub const LENDER_TYPE: u8 = 7;
|
||
|
|
pub const BORROWER_TYPE: u8 = 8;
|
||
|
|
pub const COLLATERAL_TYPE: u8 = 9;
|
||
|
|
pub const BURN_TYPE: u8 = 10;
|
||
|
|
pub const ISSUE_TOKEN_TYPE: u8 = 11;
|
||
|
|
pub const VANITY_ADDRESS_TYPE: u8 = 12;
|
||
|
|
|
||
|
|
// Coin and asset names are stored in fixed 15-byte fields.
|
||
|
|
pub const COIN_LENGTH: usize = 15;
|
||
|
|
|
||
|
|
// The fixed parent hash used only by the genesis block.
|
||
|
|
pub const GENESIS_BLOCK_HASH: &str =
|
||
|
|
"03c8e5f02c97a4f4a270dbc13ffe2e3f782f0013674b9b5e960124b89e581f38";
|
||
|
|
|
||
|
|
// The built-in genesis network entry uses localhost.
|
||
|
|
pub const GENESIS_IP: &str = "127.0.0.1";
|
||
|
|
|
||
|
|
// Reward halvings are based on this fixed block interval.
|
||
|
|
pub const BLOCKS_PER_HALVING: u32 = 9600000;
|
||
|
|
|
||
|
|
// Decimal display value for the base transfer fee percentage.
|
||
|
|
pub const TRANSFER_FEE: f64 = 0.01;
|
||
|
|
|
||
|
|
// Integer numerator and denominator used for fee math.
|
||
|
|
// example: 1 / 100 = 1%; 25/1000 = 2.5%
|
||
|
|
pub const BASE_TRANSFER_FEE_NUMERATOR: u64 = 1;
|
||
|
|
pub const BASE_TRANSFER_FEE_DENOMINATOR: u64 = 100;
|
||
|
|
|
||
|
|
// Fixed transaction fees are stored in the smallest coin unit.
|
||
|
|
pub const NON_BASE_TRANSFER_MIN_FEE: u64 = 100000000; // 1 CLC
|
||
|
|
pub const CREATE_TOKEN_FEE: u64 = 50000000000; // cost to create tokens, 500 CLC
|
||
|
|
pub const CREATE_NFT_FEE: u64 = 50000000; // cost to creat nfts, 0.5 CLC
|
||
|
|
pub const MARKETING_FEE: u64 = 100000000; // cost to add marketing record, 1 CLC
|
||
|
|
pub const SWAP_FEE: u64 = 100000000; // cost for a token swap each party must pay, 1 CLC
|
||
|
|
pub const LENDER_FEE: u64 = 300000000; // cost to create a loan, 3 CLC
|
||
|
|
pub const BORROWER_FEE: u64 = 1000000; // cost to make loan payment, 0.01 CLC
|
||
|
|
pub const COLLATERAL_FEE: u64 = 300000000; // cost to clain collateral, 3 CLC
|
||
|
|
pub const BURN_FEE: u64 = 10000; // cost to burn a token or NFT, 0.0001 CLC
|
||
|
|
pub const ISSUE_TOKEN_FEE: u64 = 10000000000; // cost to issue more of an existing token, 100 CLC
|
||
|
|
pub const VANITY_ADDRESS_FEE: u64 = 500000000; // cost to register or update a vanity address, 5 CLC
|
||
|
|
|
||
|
|
pub fn minimum_transfer_fee(value: u64, is_base_coin: bool) -> u64 {
|
||
|
|
// Base-coin transfers pay the percentage fee using integer math.
|
||
|
|
if is_base_coin {
|
||
|
|
value
|
||
|
|
.saturating_mul(BASE_TRANSFER_FEE_NUMERATOR)
|
||
|
|
.div_ceil(BASE_TRANSFER_FEE_DENOMINATOR)
|
||
|
|
} else {
|
||
|
|
// Token and NFT transfers use the fixed non-base minimum fee.
|
||
|
|
NON_BASE_TRANSFER_MIN_FEE
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Transaction groups every concrete block transaction type so block
|
||
|
|
// verification and save paths can dispatch through one enum.
|
||
|
|
#[derive(Debug, Serialize, Clone)]
|
||
|
|
pub enum Transaction {
|
||
|
|
Genesis(GenesisTransaction),
|
||
|
|
Rewards(RewardsTransaction),
|
||
|
|
Transfer(TransferTransaction),
|
||
|
|
Burn(BurnTransaction),
|
||
|
|
Token(CreateTokenTransaction),
|
||
|
|
IssueToken(IssueTokenTransaction),
|
||
|
|
Nft(CreateNftTransaction),
|
||
|
|
Marketing(MarketingTransaction),
|
||
|
|
Swap(SwapTransaction),
|
||
|
|
Lender(LoanContractTransaction),
|
||
|
|
Borrower(ContractPaymentTransaction),
|
||
|
|
Collateral(CollateralClaimTransaction),
|
||
|
|
Vanity(VanityAddressTransaction),
|
||
|
|
}
|