Introducing, the mint
Use the mint to pair a new private key with new tokens.
This commit is contained in:
parent
491ba9da84
commit
b6d8f737ca
16
Cargo.toml
16
Cargo.toml
|
@ -12,8 +12,8 @@ authors = [
|
|||
license = "Apache-2.0"
|
||||
|
||||
[[bin]]
|
||||
name = "silk-demo"
|
||||
path = "src/bin/demo.rs"
|
||||
name = "silk-historian-demo"
|
||||
path = "src/bin/historian-demo.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "silk-client-demo"
|
||||
|
@ -24,12 +24,16 @@ name = "silk-testnode"
|
|||
path = "src/bin/testnode.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "silk-genesis-block"
|
||||
path = "src/bin/genesis-block.rs"
|
||||
name = "silk-genesis"
|
||||
path = "src/bin/genesis.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "silk-genesis-file-demo"
|
||||
path = "src/bin/genesis-file-demo.rs"
|
||||
name = "silk-genesis-demo"
|
||||
path = "src/bin/genesis-demo.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "silk-mint"
|
||||
path = "src/bin/mint.rs"
|
||||
|
||||
[badges]
|
||||
codecov = { repository = "loomprotocol/silk", branch = "master", service = "github" }
|
||||
|
|
18
README.md
18
README.md
|
@ -32,27 +32,27 @@ First, build the demo executables in release mode (optimized for performance):
|
|||
```
|
||||
|
||||
The testnode server is initialized with a transaction log from stdin and
|
||||
generates a log on stdout. To create the input log, we'll need to create
|
||||
a *genesis* configuration file and then generate a log from it. It's done
|
||||
in two steps here because the demo-genesis.json file contains a private
|
||||
key that will be used later in this demo.
|
||||
generates new log entries on stdout. To create the input log, we'll need
|
||||
to create *the mint* and use it to generate a *genesis log*. It's done in
|
||||
two steps because the mint.json file contains a private key that will be
|
||||
used later in this demo.
|
||||
|
||||
```bash
|
||||
$ ./silk-genesis-file-demo > demo-genesis.json
|
||||
$ cat demo-genesis.json | ./silk-genesis-block > demo-genesis.log
|
||||
$ echo 500 | ./silk-mint > mint.json
|
||||
$ cat mint.json | ./silk-genesis > genesis.log
|
||||
```
|
||||
|
||||
Now you can start the server:
|
||||
|
||||
```bash
|
||||
$ cat demo-genesis.log | ./silk-testnode > demo-entries0.log
|
||||
$ cat genesis.log | ./silk-testnode > transactions0.log
|
||||
```
|
||||
|
||||
Then, in a separate shell, let's execute some transactions. Note we pass in
|
||||
the JSON configuration file here, not the genesis log.
|
||||
|
||||
```bash
|
||||
$ cat demo-genesis.json | ./silk-client-demo
|
||||
$ cat mint.json | ./silk-client-demo
|
||||
```
|
||||
|
||||
Now kill the server with Ctrl-C, and take a look at the transaction log. You should
|
||||
|
@ -68,7 +68,7 @@ Now restart the server from where we left off. Pass it both the genesis log, and
|
|||
the transaction log.
|
||||
|
||||
```bash
|
||||
$ cat demo-genesis.log demo-entries0.log | ./silk-testnode > demo-entries1.log
|
||||
$ cat genesis.log transactions0.log | ./silk-testnode > transactions1.log
|
||||
```
|
||||
|
||||
Lastly, run the client demo again, and verify that all funds were spent in the
|
||||
|
|
|
@ -7,6 +7,7 @@ use silk::transaction::Transaction;
|
|||
use silk::log::create_entries;
|
||||
use silk::signature::{KeyPair, KeyPairUtil, PublicKey};
|
||||
use silk::hash::Hash;
|
||||
use std::io::stdin;
|
||||
|
||||
fn transfer(from: &KeyPair, (to, tokens): (PublicKey, i64), last_id: Hash) -> Event {
|
||||
Event::Transaction(Transaction::new(&from, to, tokens, last_id))
|
||||
|
@ -16,15 +17,14 @@ fn main() {
|
|||
let alice = (KeyPair::new().pubkey(), 200);
|
||||
let bob = (KeyPair::new().pubkey(), 100);
|
||||
|
||||
let gen = Genesis::new(500);
|
||||
let gen: Genesis = serde_json::from_reader(stdin()).unwrap();
|
||||
let from = gen.keypair();
|
||||
let seed = gen.seed();
|
||||
let mut events = gen.create_events();
|
||||
events.push(transfer(&from, alice, seed));
|
||||
events.push(transfer(&from, bob, seed));
|
||||
|
||||
let entries = create_entries(&seed, events);
|
||||
for entry in entries {
|
||||
for entry in create_entries(&seed, events) {
|
||||
println!("{}", serde_json::to_string(&entry).unwrap());
|
||||
}
|
||||
}
|
|
@ -1,18 +1,14 @@
|
|||
//! A command-line executable for generating the chain's genesis block.
|
||||
|
||||
extern crate ring;
|
||||
extern crate serde_json;
|
||||
extern crate silk;
|
||||
|
||||
use silk::genesis::Genesis;
|
||||
use silk::log::verify_slice;
|
||||
use std::io::stdin;
|
||||
|
||||
fn main() {
|
||||
let gen: Genesis = serde_json::from_reader(stdin()).unwrap();
|
||||
let entries = gen.create_entries();
|
||||
verify_slice(&entries, &entries[0].id);
|
||||
for x in entries {
|
||||
for x in gen.create_entries() {
|
||||
println!("{}", serde_json::to_string(&x).unwrap());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
extern crate serde_json;
|
||||
extern crate silk;
|
||||
|
||||
use silk::genesis::Genesis;
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
let mut input_text = String::new();
|
||||
io::stdin().read_line(&mut input_text).unwrap();
|
||||
|
||||
let trimmed = input_text.trim();
|
||||
let tokens = trimmed.parse::<i64>().unwrap();
|
||||
let gen = Genesis::new(tokens);
|
||||
println!("{}", serde_json::to_string(&gen).unwrap());
|
||||
}
|
Loading…
Reference in New Issue