src/transactions/types.rs
Below is the list of transaction types and what the txtype value must be set to for each type (its number)
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;
Below is how the transaction part of a block is generated andwhat transactions it can have
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum Transaction {
Genesis(GenesisTransaction),
Rewards(RewardsTransaction),
Transfer(TransferTransaction),
Token(CreateTokenTransaction),
Nft(CreateNftTransaction),
Marketing(MarketingTransaction),
Swap(SwapTranasction),
Lender(LoanContractTransaction),
Borrower(ContractPaymentTransaction),
Collateral(CollateralClaimTransaction),
}
Below is the genesis transaction.. It is 85 bytes, combined with the head that makes genesis block 129 bytes.
#[derive(Debug, Serialize, Deserialize, Clone)] // 85 bytes
pub struct GenesisTransaction {
pub txtype: u8, // 1 byte txtype should be 0
pub timestamp: u32, // 4 bytes timestamp of blockchain creation
pub message: String, // 48 bytes mess for genesis block
pub hash: String, // 32 bytes hash of transaction
}
Below is the rewards transaction. It is 142 bytes making a block with no other transactions 186 bytes.
#[derive(Debug, Serialize, Deserialize, Clone)] // 142 bytes
pub struct RewardsTransaction {
pub txtype: u8, // 1 byte txtype should be 1
pub timestamp: u32, // 4 bytes time of block mine
pub value: u64, // 8 bytes reward for mining
pub receiver: String, // 33 bytes miner wallet address
pub hash: String, // 32 bytes hash of transaction
pub signature: String, // 64 bytes signature of hash
}
The transfer transaction handles sending coins, tokens and NFTs from one user to another. It is 198 bytes.
#[derive(Debug, Serialize, Deserialize, Clone)] // 198 bytes
pub struct TransferTransaction {
pub txtype: u8, // 1 byte txtype should be 2
pub timestamp: u32, // 4 bytes time of transaction
pub value: u64, // 8 bytes number of coins or tokens to be sent
pub coin: String, // 15 btyes this works with nfts, tokens ot coin - padd with spaces as needed
pub sender: String, // 33 bytes wallet address of sender
pub receiver: String, // 33 bytes wallet address of receiver
pub txfee: u64, // 8 bytes fee of transaction
pub hash: String, // 32 bytes hash of transaction
pub signature: String, // 64 bytes signature of hash
}
The Token Creation transaction generates tokens and is 165 bytes.
#[derive(Debug, Serialize, Deserialize, Clone)] // 165 bytes
pub struct CreateTokenTransaction {
pub txtype: u8, // 1 byte txtype should be 3
pub timestamp: u32, // 4 bytes time of creation
pub creator: String, // 33 bytes wallet address of creator
pub ticker: String, // 15 bytes ticket for token pad with spaces
pub number: u64, // 8 bytes number of tokens to create
pub txfee: u64, // 8 bytes fee of transaction
pub hash: String, // 32 bytes hash of transaction
pub signature: String, // 64 bytes signature of hash
}
The create NFT transaction is how one mints nfts and is 312 bytes.
#[derive(Debug, Serialize, Deserialize, Clone)] // 312 bytes
pub struct CreateNftTransaction {
pub txtype: u8, // 1 byte txtype should be 4 pub timestamp: u32, // 4 bytes time of creation pub creator: String, // 33 bytes wallet address of creator pub series: u8, // 1 bytes series should be 0 or 1 for no series or series pub nft_name: String, // 15 bytes name for nft or collection pad with spaces ifless than 15 cannot be same name as anyone elses nft
pub item_ipfs: String, // 46 bytes ipfs hash should start with Qm for series should be a directory hash
pub count: u32, // 4 bytes should be 1 if not a series, otherwise the number of items in the series
pub item_number: u32, // 4 bytes should be a 0 if not a series, otherwise the item number of the item in the series
pub desc: String, // 100 bytes desc should be adescription pad with spaces if not using all 100 characters.
pub txfee: u64, // 8 bytes fee of transaction
pub hash: String, // 32 bytes hash of transaction
pub signature: String, // 64 bytes signature of hash
}
The marketing transaction allows recording hits and impressions for various types of ads so advertising agencies can prove records on chain,. It is a 302 byte transaction.
#[derive(Debug, Serialize, Deserialize, Clone)] // 302 bytes
pub struct MarketingTransaction {
pub txtype: u8, // 1 byte txtype should be 5
pub timestamp: u32, // 4 bytes time of creation
pub campaign: u64, // 8 bytes identify the ad with a number
pub ad_type: String, // 6 bytes value type should be banner, social or text - buffer with 2 padded spaces for the word text
pub keyword: String, // 40 bytes keyword ad is targeting - buffer if less than 40 characters
pub displayed: String, // 100 bytes The location the ad was displayed - If longer than 100 characters truncate - If less padd with spaces
pub impression: u8, // 1 byte Update the impression of an ad often. Should be beteen 0 and 255.
pub click: u8, // 1 byte Update when an ad is clicked. Should be between 0 and 255.
pub impression_value: u16, // 2 bytes Dollar value of impression - multiply by 100
pub click_value: u16, // 2 bytes Dollar value of click - multiply by 100
pub advertiser: String, // 33 bytes Wallet of the Ad Agency NOT the client
pub txfee: u64, // 8 bytes fee of transaction
pub hash: String, // 32 bytes hash of transaction
pub signature: String, // 64 bytes signature of hash
}
The token swap transaction allows 2 people to swap tokens, tokens, coins, assets, whatever without the need for any middlemen or contracts. It is 309 bytes and requires two parties sign.
#[derive(Debug, Serialize, Deserialize, Clone)] // 309 bytes
pub struct SwapTranasction {
pub txtype: u8, // 1 byte txtype should be 6
pub timestamp: u32, // 4 bytess time of creation
pub ticker1: String, // 15 bytes The ticker of the first token matches the sender1
pub value1: u64, // 8 bytes The amount of the first token to swaped by sender1
pub ticker2: String, // 15 bytes The ticket of the second token matches the sender2
pub value2: u64, // 8 bytes The amount of the second token to be swaped by sender2
pub sender1: String, // 33 bytes The wallet address of sender1
pub sender2: String, // 33 btyes The wallet address of sender2
pub tip1: u64, // 8 bytes Tip the miner must be in same token as ticker1 and must be at least 1% of transaction
pub tip2: u64, // 8 bytes Tip the miner must be in same token as ticker2 and must be at least 1% of transaction
pub txfee1: u64, // 8 bytes The fee of sender1
pub txfee2: u64, // 8 bytes The fee of sender2
pub hash: String, // 32 bytes The hash of the transaction
pub signature1: String, // 64 bytes The signature of sender1 for the hash
pub signature2: String, // 64 bytes The signature of sender2 for the hash
}
This is a loan creation transaction. It allows one person to borrow coins or tokens from another using onchain digital collateral of NFTs or tokens. Its is a 304 byte transaction and requires 2 signatures.
#[derive(Debug, Serialize, Deserialize, Clone)] // 304 bytes
pub struct LoanContractTransaction {
pub txtype: u8, // 1 byte txtype should be 7
pub timestamp: u32, // 4 bytes time of creation -- this is when the contract begins
pub loan_coin: String, // 15 bytes Coin or token being loaned
pub loan_amount: u64, // 8 bytes How many coins/tokens being loaned
pub lender: String, // 33 bytes The wallet address of the lender
pub collateral: String, // 15 btyes Mame of tokens or NFT being used for collateral
pub collateral_amount: u64, // 8 bytes Amount of tokens or 1 in an NFT
pub borrower: String, // 33 bytes The wallet address of the borrower
pub payment_period: String, // 1 byte d (days), w (weeks), m (months)
pub payment_number: u8, // 1 byte How many payments it total will be mde
pub payment_amount: u64, // 8 bytes Amount of each payment
pub grace_period: u8, // 1 byte How many payments before collateral can be claimed by lender
pub max_late_value: u64, // 8 bytes Max value payments can be behind befor collateral can be claimed by lender
pub txfee: u64, // 8 bytes The fee of the transaction, to be paid by the lender
pub hash: String, // 32 bytes The hash of the transaction
pub signature1: String, // 64 bytes The signature of lender for the hash
pub signature2: String, // 64 bytes The signature of borrower for the hash
}
The contract payment transaction is how you pay back loan. It is a 190 byte transaction.
#[derive(Debug, Serialize, Deserialize, Clone)] // 190 bytes
pub struct ContractPaymentTransaction {
pub txtype: u8, // 1 byte txtype should be 8
pub timestamp: u32, // 4 bytes timestamp of payment
pub payback_amount: u64, // 8 bytes The amount of loaded token to pay back
pub contract_hash: String, // 32 bytes The hash of the loan contract
pub address: String, // 33 bytes The wallet address of whoever is making the payment
pub tip: u64, // 8 bytes Tip the miner must be in same token as loan and must be at least 1% of payment
pub txfee: u64, // 8 bytes The fee of the transaction
pub hash: String, // 32 bytes The hash of the transaction
pub signature: String, // 64 bytes The signature of the transaction hash
}
The claim collateral transaction is used to reclaim the collateral of a contract upon final payment, or used to claim the collateral by a lender if the loan is defaulted. It is a 174 byte transaction.
#[derive(Debug, Serialize, Deserialize, Clone)] // 174 bytes
pub struct CollateralClaimTransaction {
pub txtype: u8, // 1 byte txtype should be 9
pub timestamp: u32, // 4 bytes timestamp of claim
pub contract_hash: String, // 32 bytes The hash of the loan contract
pub address: String, // 33 bytes The wallet addressof ethe buyer of the sender; no one else can attempt to claim collateral
pub txfee: u64, // 8 bytes The fee of the transaction
pub hash: String, // 32 bytes The hash of the transaction
pub signature: String, // 64 bytes The signature of the transaction hash
}