美文网首页
solana应用开发1

solana应用开发1

作者: Feather轻飞 | 来源:发表于2021-09-19 01:09 被阅读0次
executing smart contract

base element: Account

Data being stored in the blockchain is living inside the account

Data into Account   Account in blockchain

Account holds money

Smart Contract (Program)inside the account

Smart Contract in its binary form is data of some account

Account must be owned by a program

only way be debited the account owner is the one doing the actions

2. Rent

3. Compute Limit

Structure 

Transaction 

Block

Transaction:Metadata Accounts Instructions

1) Array of signatures(that may be needed in order to get the permissions to do various tasks within the transaction

for example, crediting the lamports that is taking it out of one account

and sending it off to another account

+ writing into the data of an account and modifying that data

2) message

(a)top:header(bunch of metadata,count of signatures, count of read-only addresses that require signatures,count of read-only addresses that do not require signatures)

(b)middle: array of account addresses

(required because when you launch your individual instructions, these are the calls being made to the specific program that need to do work

so those programs will make a claim about what accounts they are going to accessing for various reasons during their run)

(Check:these account they claimed access to must be listed out in the

total array of all account addresses being accessed in the message

so within that transaction)

(c) previous block hash:a big element of how solana works and how solana creates consensus and maintains its security is by using time as a mechanism in part to do that work

they have something called proof of history as their consensus mechanism

(proof of stake)allow other nodes to check the validity 

check previous block hash to see whatever is requested during this transaction is neither too old or way into the future

either every 

if one fails others fail。one instruction fails the whole thing fails

(理解)

(d) instructions

1-ProgramID (pointing the account parent that is holding the program inside its data

2-List of Accounts you are claiming your program is going to need access to(accounts must be in the master list in order for instructions to be valid)

3-Checks (owner check。 specific:program acting on the correct set of accounts)

4- data u8 byte array (open ended) any type of data including objects

lib.rs

program entrypoint

mirror of program_id, accounts and instruction data

accounts:list of accounts that your specific program need access to 

instruction data u8:

//Iterating accounts is safer then indexing!

let accounts_iter = &mut accounts.iter();

(iterable , you take the first element you take the entire array then you take the next on it which gives you the initial next element.

Getting reference to the mutable array)

//Get the account to say hello to

let account = next_account_info(accounts_iter)?;

// instead of calling next, next, next we just use this helper tool 

//grab the right specific account in the right order

//everytime this get called, it just gives me the immediate next account

3) The account must be owned by program in order to modify its data

if account.owner != program_id { return Err(ProgramError::IncorrectProgramId};

4)Increment and store the number of times the account has been greeted

let mut greeting_account = GreetingAccount::try_from_slice(&account.data.borrow())?;

//data, whatever data we want. we need to encode and decode properly

//went from byte array and it decoded it into its actual type instance

//then after doing whatever it is that it needed to do it's now taking it and encoding it back into the data

let mut greeting_account = GreetingAccount :: try_from_slice(&account.data.borrow())?

//bytearray then decode it into its actual type instance

let data = &mut &mut account.data.borrow_mut()[..];

greeting_account.serialize(data)

//taking it and encoding it

让GreetingAccount inherit from derive后面的那些,不需要写代码

automatically apply to this type(traits in rust)

by doing this give greetingaccount ability to encode and decode itself

2)

相关文章

  • solana应用开发1

    base element: Account Data being stored in the blockchain...

  • Solana Anchor教程1

    1. 教程1:Getting Started With Anchor In A React Project (Qu...

  • Solana 事件

    Solana 停止出块已经 7 个小时了,到现在还没有修复,算是比较严重的事故了,印象中还没那个主网有这么长的停滞...

  • 钉钉小程序资料连载中...

    1.应用开发场景 企业内部开发 说明:企业内部开发的应用无法上架至钉钉应用市场,仅供内部使用。可用应用类型:E应用...

  • OneNet5.0 新版产品应用开发API调用指南(三) 应用开

    应用开发API 入口: 第一部分 应用开发流程及项目分组 一. 应用开发流程 https://open.iot.1...

  • 推送通知-极光推送

    1:在极光开发者服务创建应用应用名称应用图标APNS开发证书(p12文件)(开发证书密码:-安装开发者证书到钥匙串...

  • 快速应用开发

    快速应用开发(RAD)是瀑布模型的高速变种,通过使用基于构件的开发方法获得快速开发。 快速应用开发的基本思想:1、...

  • Android初级面试题

    Android初级: 1.了解Android系统架构 应用层: Java应用开发工程师开发的所有应用程序比如地图,...

  • iOS开发集锦之 2017.06.13

    1. ARKit 开发系列(1)----Xcode开发ARKit应用 作者: Albert描述: 1.要求: Ma...

  • MetInfo开发文档

    MetInfo应用开发文档 1. 开发准备 1.1 前言 MetInfo应用制作介绍MetInfo企业网站管理系统...

网友评论

      本文标题:solana应用开发1

      本文链接:https://www.haomeiwen.com/subject/tltzwltx.html