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"
|
license = "Apache-2.0"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "silk-demo"
|
name = "silk-historian-demo"
|
||||||
path = "src/bin/demo.rs"
|
path = "src/bin/historian-demo.rs"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "silk-client-demo"
|
name = "silk-client-demo"
|
||||||
|
@ -24,12 +24,16 @@ name = "silk-testnode"
|
||||||
path = "src/bin/testnode.rs"
|
path = "src/bin/testnode.rs"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "silk-genesis-block"
|
name = "silk-genesis"
|
||||||
path = "src/bin/genesis-block.rs"
|
path = "src/bin/genesis.rs"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "silk-genesis-file-demo"
|
name = "silk-genesis-demo"
|
||||||
path = "src/bin/genesis-file-demo.rs"
|
path = "src/bin/genesis-demo.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "silk-mint"
|
||||||
|
path = "src/bin/mint.rs"
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
codecov = { repository = "loomprotocol/silk", branch = "master", service = "github" }
|
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
|
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
|
generates new log entries on stdout. To create the input log, we'll need
|
||||||
a *genesis* configuration file and then generate a log from it. It's done
|
to create *the mint* and use it to generate a *genesis log*. It's done in
|
||||||
in two steps here because the demo-genesis.json file contains a private
|
two steps because the mint.json file contains a private key that will be
|
||||||
key that will be used later in this demo.
|
used later in this demo.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ ./silk-genesis-file-demo > demo-genesis.json
|
$ echo 500 | ./silk-mint > mint.json
|
||||||
$ cat demo-genesis.json | ./silk-genesis-block > demo-genesis.log
|
$ cat mint.json | ./silk-genesis > genesis.log
|
||||||
```
|
```
|
||||||
|
|
||||||
Now you can start the server:
|
Now you can start the server:
|
||||||
|
|
||||||
```bash
|
```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
|
Then, in a separate shell, let's execute some transactions. Note we pass in
|
||||||
the JSON configuration file here, not the genesis log.
|
the JSON configuration file here, not the genesis log.
|
||||||
|
|
||||||
```bash
|
```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
|
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.
|
the transaction log.
|
||||||
|
|
||||||
```bash
|
```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
|
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::log::create_entries;
|
||||||
use silk::signature::{KeyPair, KeyPairUtil, PublicKey};
|
use silk::signature::{KeyPair, KeyPairUtil, PublicKey};
|
||||||
use silk::hash::Hash;
|
use silk::hash::Hash;
|
||||||
|
use std::io::stdin;
|
||||||
|
|
||||||
fn transfer(from: &KeyPair, (to, tokens): (PublicKey, i64), last_id: Hash) -> Event {
|
fn transfer(from: &KeyPair, (to, tokens): (PublicKey, i64), last_id: Hash) -> Event {
|
||||||
Event::Transaction(Transaction::new(&from, to, tokens, last_id))
|
Event::Transaction(Transaction::new(&from, to, tokens, last_id))
|
||||||
|
@ -16,15 +17,14 @@ fn main() {
|
||||||
let alice = (KeyPair::new().pubkey(), 200);
|
let alice = (KeyPair::new().pubkey(), 200);
|
||||||
let bob = (KeyPair::new().pubkey(), 100);
|
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 from = gen.keypair();
|
||||||
let seed = gen.seed();
|
let seed = gen.seed();
|
||||||
let mut events = gen.create_events();
|
let mut events = gen.create_events();
|
||||||
events.push(transfer(&from, alice, seed));
|
events.push(transfer(&from, alice, seed));
|
||||||
events.push(transfer(&from, bob, seed));
|
events.push(transfer(&from, bob, seed));
|
||||||
|
|
||||||
let entries = create_entries(&seed, events);
|
for entry in create_entries(&seed, events) {
|
||||||
for entry in entries {
|
|
||||||
println!("{}", serde_json::to_string(&entry).unwrap());
|
println!("{}", serde_json::to_string(&entry).unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,18 +1,14 @@
|
||||||
//! A command-line executable for generating the chain's genesis block.
|
//! A command-line executable for generating the chain's genesis block.
|
||||||
|
|
||||||
extern crate ring;
|
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
extern crate silk;
|
extern crate silk;
|
||||||
|
|
||||||
use silk::genesis::Genesis;
|
use silk::genesis::Genesis;
|
||||||
use silk::log::verify_slice;
|
|
||||||
use std::io::stdin;
|
use std::io::stdin;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let gen: Genesis = serde_json::from_reader(stdin()).unwrap();
|
let gen: Genesis = serde_json::from_reader(stdin()).unwrap();
|
||||||
let entries = gen.create_entries();
|
for x in gen.create_entries() {
|
||||||
verify_slice(&entries, &entries[0].id);
|
|
||||||
for x in entries {
|
|
||||||
println!("{}", serde_json::to_string(&x).unwrap());
|
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