- tags: Web3
Learn journal of Starcoin Web3 StarTrek Program, check the follow “Links to this note”.
Learn journal of Starcoin Web3 StarTrek Program, check the follow “Links to this note”.
tags: Starcoin Web3 StarTrek, Sign Message Invocation Path Dapp request personal_sign1 const msg = `0x${Buffer.from(exampleMessage, 'utf8').toString('hex')}` console.log({ msg }) const networkId = networkDiv.innerHTML const extraParams = { networkId } const sign = await window.starcoin.request({ method: 'personal_sign', // params: [msg, from, 'Example password'], // extraParams = params[2] || {}; means it should be an object: // params: [msg, from, { pwd: 'Example password' }], params: [msg, from, extraParams], }) Starmask handling request signPersonalMessage keyringController.signPersonalMessage(cleanMsgParams) 2 , 3 3 types of keyring:4 SimpleKeyring.signPersonalMessage HdKeyring.signPersonalMessage HdKeyringAptos.signPersonalMessage utils.signedMessage.generateSignedMessage5 ...
tags: Move,Starcoin Web3 StarTrek Bedrock – Object-capability model In my words, Move is kind of a Resource-Oriented Programming language. The resource is represented by struct in Move, aka object in other programming language. By the way, the resource in Move is the struct which cannot be copied and cannot be dropped1. Distinct from other programming language, objects are stored in memory, resource in Move can store to the chain’s global storage. ...
tags: Starcoin Web3 StarTrek,Move When I start learning Move and looking at the stdlib starcoin-framework and starcoin-framework-commons. Then I realized there are must some magic during the block execution in runtime. To roll the world, the runtime should provide some built in types and call some function in the stdlib. How does StarcoinVM Validate Transactions? As a miner, it’s responsible for executing block, it follows: Received some transactions from P2P network: EventHandler of PeerTransactionsMessage. ...
tags: Starcoin Web3 StarTrek Start node with console: $ ./target/debug/starcoin -d ~/.starcoin -n dev console In console type: starcoin% dev log level debug Note: starcoin% is the prompt. Then we can see debug log in ~/.starcoin/dev/starcoin.log.
tags: Move,Starcoin Web3 StarTrek source: Blackshear, Sam, Evan Cheng, David L Dill, Victor Gao, Ben Maurer, Todd Nowacki, Alistair Pott, et al. “Move: A Language With Programmable Resources,” n.d., 26.
tags: Starcoin Web3 StarTrek,Blockchain,Smart contracts
tags: Starcoin Web3 StarTrek,Account-Model Blockchain Systems We can create an account by wallet like MetaMask or StarMask, but I’m curious about how an account is created on the blockchain system. As a wallet has been embedded in the starcoin node, we can use it to create an account as follow: $ ./target/debug/starcoin -d ~/.starcoin -n dev account create -p my-pass { "ok": { "address": "0x2f1aeb63bd30d8eb841d6a941c5d6df3", "is_default": false, "is_readonly": false, "public_key": "0x91f79bdd9ced49332bf85b751d02339e05aff047c386d0c14b380d8519d2fb4b", "receipt_identifier": "stc1p9udwkcaaxrvwhpqad22pchtd7vy2276p" } } As above we can see our account has been created, and the address is: 0x2f1aeb63bd30d8eb841d6a941c5d6df3. We’ll find some files are created, if we check our local directory at ~/.starcoin/dev: ...
tags: libp2p,Starcoin Web3 StarTrek source: https://docs.rs/libp2p/0.45.1/libp2p/tutorials/index.html Ping: Four necessary traits Identity: PeerId and corresponding Keypair Transport: send and receive bytes on the network. NetworkBehaviour: decode or encode the bytes from the Transport. Swarm: drives both a Transport and a NetworkBehaviour forward. use futures::StreamExt; use libp2p::ping::{Ping, PingConfig}; use libp2p::{identity, Multiaddr, PeerId, Swarm}; use std::error::Error; #[async_std::main] async fn main() -> Result<(), Box<dyn Error>> { // First we need to create a network identity. let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); println!("Local peer id: {:?}", local_peer_id); // Then construct a transport: defines how to send bytes on the network. let transport = libp2p::development_transport(local_key).await?; // NetworkBehaviour defines what bytes to send on the network. let behaviour = Ping::new(PingConfig::new().with_keep_alive(true)); // Swarm connects transport and behaviour together: // // 1. Passing commands from NetworkBehaviour to the Transport. // 2. As well ass events from the Transport to the NetworkBehaviour. let mut swarm = Swarm::new(transport, behaviour, local_peer_id); swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?; if let Some(addr) = std::env::args().nth(1) { let remote: Multiaddr = addr.parse()?; swarm.dial(remote)?; println!("Dialed {}", addr); } loop { match swarm.select_next_some().await { libp2p::swarm::SwarmEvent::NewListenAddr { listener_id: _, address, } => println!("Listening on {:?}", address), libp2p::swarm::SwarmEvent::Behaviour(event) => println!("{:?}", event), _ => {} } } Ok(()) }
tags: P2P,libp2p,Starcoin Web3 StarTrek
tags: P2P,Starcoin Web3 StarTrek,Network source: https://docs.libp2p.io/ A set of protocols for peer identity, discover, routing, transport and more. Peer-to-peer network Peers or nodes communicate with oen another directly, it’s different from the client-server architecture. libp2p Solved Transport abstract data transmission and receipt to adapte many protocols, include the future protocols. Identity use public key cryptography as the basis of peer identity, with this: It gives each peer a globally unique “name”, in the form of a PeerId. PeerId allows anyone to retreve the public key for the identified peer, which enables secure communication between peers. Security libp2p supports “upgrading” a connection provided by a transport into a securely encrypted channel. Currently support; ...
tags: Starcoin Web3 StarTrek,Blockchain
tags: Starcoin Web3 StarTrek,starcoin issue solving Today I saw this issue: starcoin#3450 at GitHub, I decide to give it a try. The corresponding type VMStatus is defined out of starcoin’s reposiotry, here. The work need to be done seems are: convert function from u16 to a readable string. convert status_code from StatusCode to a readable string. Let’s take a look at StatusCode first, StatusCode is a enum that contains lot of variants, WOW! My intuition is that can we just get the name of the variant by it’s value. Or I’ll write an ugly match that contains tons of arms. Maybe there already existed some similar code, Let me do a search. ...
tags: Starcoin Web3 StarTrek
tags: Merkle tree,Blockchain,Starcoin Web3 StarTrek source: Gao, Zhenhuan, Yuxuan Hu, and Qinfan Wu. “Jellyfish Merkle Tree,” n.d., 12. What is Addressable mean? It means the leaf node in the tree can be found by an address. The address encoded the path to the leaf node, for example, a leaf node in a binary tree, which has 3 level. Its address may be encoded to 010, the corresponding path is: left->right->left: 0 1 0 + + + v v v left right left root / \ H1 H2 /\ /\ D1 D2 D3 D4 As we can see, the address 010 leads us to the leaf node D2. ...
tags: Starcoin Web3 StarTrek,Account-Model Blockchain Systems source: https://academy.horizen.io/technology/expert/utxo-vs-account-model/
tags: Starcoin Web3 StarTrek,Ethereum,Merkle tree
tags: Starcoin Web3 StarTrek,Merkle tree,Ethereum Powers the widely known Ethereum network.
tags: Starcoin Web3 StarTrek,Blockchain Overview Block is the basic element in a blockchain system, as we known blockchain system is just a ledger, which means a bookkeeping1 that recording of financial transactions. In the blockchain system, those transactions are stored in the blocks. In each block, the data stored in may look like: TXN FROM TO VALUE #0 God Cale 100 #1 Cale Alice 10 #2 Alice Bob 1 #3 Bob Mike 0.5 Then what’s a blockchain? Just simply chain the blocks together, usually add a field to point to its parent: ...
tags: Merkle tree,Starcoin Web3 StarTrek
tags: Starcoin Web3 StarTrek,Sparse Merkle Tree,Merkle tree,LSM-Tree,Account-Model Blockchain Systems source: Gao, Zhenhuan, Yuxuan Hu, and Qinfan Wu. “Jellyfish Merkle Tree,” n.d., 12. JMT(Jellyfish Merkle Tree) a LSM-tree based Implementation of Sparse Merkle Tree Inspired by Patricia Merkle Tree and has been implemented in Rust, but it is language-independent. Merkel tree fits pretty well as an authenticated key-value store holding a huge amount of data in a tamper-proof way. Two major concerns where people have been trying to achieve some enhnacements: ...
tags: Starcoin Web3 StarTrek, Proof-of-work Generate nonce (random data) as salt to join to the data of block to be hash. The goal is to find a hash value that less than target. The target is influenced by difficulty. As the difficulty gets bigger and the target will be smaller, which means more difficult to find. pub fn difficult_to_target(difficulty: U256) -> U256 { U256::max_value() / difficulty }
tags: Starcoin Web3 StarTrek,Blockchain source: Wikipedia: Merkle tree Starcoin Cookbook What is a Merkle tree. Merkle tree is a hash tree, named after Ralph Merkle, who patented in 1979. Most implementations of them are binary, which means two child nodes under each node. Why the merkle tree is important to the peer-to-peer network? The main purpose of a merkle tree is to ensure the data we received from a peer-to-peer network are undamaged and unaltered, it’s important as the data were splitted into many blocks and stored in multiple nodes in the network. ...
tags: Starcoin Web3 StarTrek The documentation of Starcoin are written in multiple places: The Developers Documentation on the main site English Version Chinese Version The Starcoin Cookbook English Version Chinese Version
tags: Starcoin Web3 StarTrek Why compile starcoin from source? Why not download a released binary? Because I want to contribute code to it, maybe in the future. But the toolchain is awesome, the progress is very simple. Just two steps: Clone the code from GitHub git clone git@github.com:starcoinorg/starcoin.git Run scripts/dev_setup.sh: cd starcoin ./scripts/dev_setup.sh Then we are ready to compile: cargo build Wait? You haven’t install Rust yet? Please refer to Getting started. ...