- 浏览: 762728 次
- 性别:
- 来自: 深圳
文章列表
// SPDX-License-Identifier: MIT
pragma solidity >= 0.6.0 < 0.9.0;
import '@openzeppelin/contracts/utils/math/SafeMath.sol';
import "hardhat/console.sol";
interface ICoinFlip{
function flip(bool _guess) external returns (bool);//这里函数可见性要改成external
}
contract CoinFlip ...
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)