- 浏览: 722706 次
- 性别:
- 来自: 深圳
文章列表
solidity工具
- 博客分类:
- solidity
1.前置准备,运行一个新项目
mkdir my-project
cd my-project
npm init --yes
npm install --save-dev hardhat@2.8.2 -g
npm install --save-dev @nomiclabs/hardhat-truffle5 @nomiclabs/hardhat-web3 web3
2.启动本地
npx hardhat node
3.设置自动
await network.provider.send("evm_setAutomine", [false]);
4.启动区间
await networ ...
maven:https://www.runoob.com/maven/maven-pom.html
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd">
& ...
fn main() {
//if let
let favorite_color: Option<&str> = None;//std::option::Option::Some("str");
let is_tuesday = false;
let age: Result<u8, _> = "34".parse();
if let Some(color) = favorite_color {
println!("Using your fav ...
rust mutex
- 博客分类:
- rust
use std::sync::{Arc,Mutex};
use std::thread::spawn;
#[test]
pub fn mutex(){
let m = Mutex::new(5);
{
let mut num = m.lock().unwrap();
*num = 6;
}
println!("m:{:?}",m);
let counter = Arc::new(Mutex::new(0));
let mut handles = vec![];
...
rust channel
- 博客分类:
- rust
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
pub fn f_channel() {
let (tx, rx) = mpsc::channel();
let tx1 = tx.clone();
thread::spawn(move || {
let vec = vec![
"hi",
"tom",
"aaa",
...
Box,Rc,RefCell都是不可变借用,只不过RefCell是运行时检查,Box和RefCell是可变的,Rc不可变但同一个数据可以有多个拥有者
Box<T>类型具有已知大小并指向在堆上分配的数据。该 Rc<T>类型跟踪堆上数据的引用次数,以便数据可以有多个所有者。具有内部可变性的RefCell<T>类型为我们提供了一种类型,当我们需要不可变类型但需要更改该类型的内部值时可以使用该类型;它还在运行时而不是在编译时强制执行借用规则
use std::ops::Deref;
use std::rc::Rc;
use std::cell::RefC ...
#[derive(Debug)]
struct Rectangle {
width: u32,
height: u32,
}
impl Rectangle {
fn can_hold(&self, other: &Rectangle) -> bool {
self.width > other.width && self.height > other.height
}
}
pub struct Guess {
value: i32,
}
impl Gu ...
fn longest<'info>(x: &'info str, y: &'info str) -> &'info str {
if x.len() > y.len() {
x
} else {
y
}
}
//传入的和返回的有相同的生命周期,不然调用在{}如果传入的没了,返回的跳出{}还存在就会有问题
// fn longest2<'a>(x: &str, y: &str) -> &'a str {
// let r ...
use std::collections::HashMap;
fn main() {
//hashmap会根据首次存放任意类型的数据
let mut map = HashMap::new();
map.insert(1,2);
for (i,v) in map {
println!("{} {}",i,v);
}
let mut map2 = HashMap::new();
map2.insert(String::from("aaa"),2);
ma ...
npm install web3
let Web3 = require('web3');
shortHexString = Web3.utils.asciiToHex('I have 100!')
const padded = ethers.utils.hexZeroPad(shortHexString, 32)
1.先验证交易大小,类型,签名,最小gas等
2.尝试把有效交易添加到queue,all,priced队列,当新交易的feeCap和feeTip都是旧交易的1.1倍以上时就可以replace
3.从queue队列出取出交易并尽可能地将事务移到pending
4.删除那些nonce太低及余额不足的失效事务
5.如果设置了baseFee(FeeCap),使用的是eip1559的DynamicFeeTx,则优先比较feeTip,谁的小费高谁排前面,但是LegacyTx的gasPrice也算作了feeTip,原有的gasPrice高排前面的规则依然生效
共识:PoS
1.Solana生态系统中有多个角色(领导者、验证者、存档者等)。与DPoS区块链不同,Solana不会在网络参与者之间委派这些角色,而是由Solana节点履行网络的所有角色。
2.网络中都有且仅有一个Leader。每个验证者节点都具有与Leader节点相同的硬件能力,并且能够通过基于PoS算法的选举来成为Leader.
3.每个验证节点使用同一种算法来选择预期的领导者。当验证节点收到一个新的签名账本条目时,可以肯定某条目是来自预期的领导者。分配给每位领导者的插槽顺序称为leader schedule(领导者安排表),Solana以固定的时间间隔(称为插槽)轮换领导者。
4. ...