Solana介绍Solana是一条高性能的L1公链ProofofHistory(PoH)用于在不信任彼此的计算机之间进行时间同步比没有时钟的区块链快好多倍(1k,10k)部署到Solana区块链上的代码称为program(合约)要与progr
<!--StartFragment-->
Solana 是一条高性能的 L1 公链
Proof of History
(PoH)
部署到 Solana 区块链上的代码称为 program(合约)
部署上去的合约通过 sdk 或者 cli 进行通信
sdk
编写 dapp
<!--EndFragment-->
<!--StartFragment-->
<!--EndFragment-->
pub struct Account {
/// lamports in the account
pub lamports: u64,
/// data held in this account
#[serde(with = "serde_bytes")]
pub data: Vec<u8>,
/// the program that owns this account. If executable, the program that loads this account.
pub owner: Pubkey,
/// this account's data contains a loaded program (and is now read-only)
pub executable: bool,
/// the epoch at which this account will next owe rent
pub rent_epoch: Epoch,
}
<!--StartFragment-->
账号
,就是一串Ed25519的私钥
用户账号的地址
, 则是这私钥对应的公钥
key-pair
公钥 + 密码
得到 私钥
, 再用私钥操作 Account
指令
的打包,所以起内容主要就是各个交易指令,以及相应指令对应的发起人
和签名
pub struct Message {
/// The message header, identifying signed and read-only `account_keys`.
/// Header values only describe static `account_keys`, they do not describe
/// any additional account keys loaded via address table lookups.
pub header: MessageHeader,
/// List of accounts loaded by this transaction.
#[serde(with = "short_vec")]
pub account_keys: Vec<Pubkey>,
/// The blockhash of a recent block.
pub recent_blockhash: Hash,
/// Instructions that invoke a designated program, are executed in sequence,
/// and committed in one atomic transaction if all succeed.
///
/// # Notes
///
/// Program indexes must index into the list of message `account_keys` because
/// program id's cannot be dynamically loaded from a lookup table.
///
/// Account indexes must index into the list of addresses
/// constructed from the concatenation of three key lists:
/// 1) message `account_keys`
/// 2) ordered list of keys loaded from `writable` lookup table indexes
/// 3) ordered list of keys loaded from `readable` lookup table indexes
#[serde(with = "short_vec")]
pub instructions: Vec<CompiledInstruction>,
/// List of address table lookups used to load additional accounts
/// for this transaction.
#[serde(with = "short_vec")]
pub address_table_lookups: Vec<MessageAddressTableLookup>,
}
pub enum VersionedMessage {
Legacy(LegacyMessage),
V0(v0::Message),
}
pub struct VersionedTransaction {
/// List of signatures
#[serde(with = "short_vec")]
pub signatures: Vec<Signature>,
/// Message to sign.
pub message: VersionedMessage,
}
<!--StartFragment-->
交易指令 (Instruction) 定义:Code
程序 id
, account 资源
, data 数据
<!--EndFragment-->pub struct CompiledInstruction {
/// Index into the transaction keys array indicating the program account that executes this instruction.
pub program_id_index: u8,
/// Ordered indices into the transaction keys array indicating which accounts to pass to the program.
#[serde(with = "short_vec")]
pub accounts: Vec<u8>,
/// The program input data.
#[serde(with = "short_vec")]
pub data: Vec<u8>,
}
<!--StartFragment-->
系统合约
系统合约是由节点在部署的时候生成的,普通用户无法更新,他们像普通合约一样,可以被其他合约或者 RPC 进行调用
常见的系统合约
System Program: 创建账号,转账等作用
BPF Loader Program: 部署和更新合约
Vote program: 创建并管理用户 POS 代理投票的状态和奖励
….
普通合约
<!--EndFragment--> <!--StartFragment-->
一般合约
,他的 Owner 都是BPF Loader
Token合约
→ SPL Token Program
<!--EndFragment--> <!--StartFragment-->
Solana 区块链引入了一种独特的资金模型来处理账户存储空间的费用,称为“租金”(Rent
)
交易费用 gas fee 和 rent 是两个东西,交易费是为了处理网络上的交易或指令,如转账、执行智能合约操作等
租金率
租金豁免
垃圾收集
永久存储的条件
<!--EndFragment--> <!--StartFragment-->
在以太坊中,普通代币被一个叫 ERC20 的提案定了规范,可以认为普通代币合约统一叫做 ERC20 代币,在 Solana 中,这个 ERC20 代币就是 SPL 代币
<!--EndFragment--> 创建代币可以使用像GTokentool这样的一键发币平台,无代码操作,简单方便。
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!