Browse Source

added first files and design notes

master
Maribel B. Lauerman 3 years ago
committed by Brooke L. Rediker
parent
commit
f859ab71cf
  1. 3
      .gitmodules
  2. 4
      _data/timelog.yml
  3. 7
      block0.yml
  4. 10
      config.yml
  5. 1
      execution-notes.md
  6. 120
      misc.pm
  7. 13
      notes.md
  8. 12
      tx.yml

3
.gitmodules

@ -0,0 +1,3 @@
[submodule "websocketd"]
path = websocketd
url = http://holoGit.ml.ipns.localhost:8080/wpreisser/websocketd.git

4
_data/timelog.yml

@ -0,0 +1,4 @@
--- # timelog
1623740460598930744: start toptal design analysis -- ~rg/toychain
1623748350994233358: stop toptal -- ~rg/toychain
1623820719262653597: start toptal -- /drg/toychain

7
block0.yml

@ -0,0 +1,7 @@
--- # block genesis
n: 0 # blocknumber (on 32bit max block-number : 4294967296)
txroot: QmNonce+qmerkle-without-zeros
# echo -n '' | ipfs add
txprev: QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH
# ipfs object new unixfs-dir
payload: QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn

10
config.yml

@ -0,0 +1,10 @@
--- # toychain's config
apis:
- 127.0.0.1:8091
- 127.0.0.2:8093
- 127.0.0.3:8095
- 127.0.0.4:8097
- 127.0.0.5:8099
# network = api+1
difficulty: 2
reward: 100

1
execution-notes.md

@ -13,5 +13,6 @@ git crypt lock
gpg --decrypt local.key.asc | git-crypt unlock -
git remote add toptal git@git.toptal.com:screening/Michel-Combes
git push toptal master
```

120
misc.pm

@ -0,0 +1,120 @@
#!/usr/bin/perl
#
# Intent:
# re-usable routines ...
#
# Note:
# This work has been done during my time at Doctor I·T
#
# -- Copyright drit, 2021 --
#
package misc;
require Exporter;
@ISA = qw(Exporter);
# Subs we export by default.
@EXPORT = qw();
# Subs we will export if asked.
#@EXPORT_OK = qw(nickname);
@EXPORT_OK = grep { $_ !~ m/^_/ && defined &$_; } keys %{__PACKAGE__ . '::'};
use strict;
# The "use vars" and "$VERSION" statements seem to be required.
use vars qw/$dbug $VERSION/;
# ----------------------------------------------------
our $VERSION = sprintf "%d.%02d", q$Revision: 0.0 $ =~ /: (\d+)\.(\d+)/;
my ($State) = q$State: Exp $ =~ /: (\w+)/; our $dbug = ($State eq 'dbug')?1:0;
# ----------------------------------------------------
$VERSION = &version(__FILE__) unless ($VERSION ne '0.00');
# -----------------------------------------------------------------------
sub khash { # keyed hash
use Crypt::Digest qw();
my $alg = shift;
my $data = join'',@_;
my $msg = Crypt::Digest->new($alg) or die $!;
$msg->add($data);
my $hash = $msg->digest();
return $hash;
}
# -----------------------------------------------------------------------
sub version {
#y ($atime,$mtime,$ctime) = (lstat($_[0]))[8,9,10];
my @times = sort { $a <=> $b } (lstat($_[0]))[9,10]; # ctime,mtime
my $vtime = $times[-1]; # biggest time...
my $version = &rev($vtime);
if (wantarray) {
my $shk = &get_shake(160,$_[0]);
print "$_[0] : shk:$shk\n" if $dbug;
my $pn = unpack('n',substr($shk,-4)); # 16-bit
my $build = &word($pn);
return ($version, $build);
} else {
return sprintf '%g',$version;
}
}
# -----------------------------------------------------------------------
sub rev {
my ($sec,$min,$hour,$mday,$mon,$yy,$wday,$yday) = (localtime($_[0]))[0..7];
my $rweek=($yday+&fdow($_[0]))/7;
my $rev_id = int($rweek) * 4;
my $low_id = int(($wday+($hour/24)+$min/(24*60))*4/7);
my $revision = ($rev_id + $low_id) / 100;
return (wantarray) ? ($rev_id,$low_id) : $revision;
}
# -----------------------------------------------------------------------
sub fdow {
my $tic = shift;
use Time::Local qw(timelocal);
## 0 1 2 3 4 5 6 7
#y ($sec,$min,$hour,$day,$mon,$year,$wday,$yday)
my $year = (localtime($tic))[5]; my $yr4 = 1900 + $year ;
my $first = timelocal(0,0,0,1,0,$yr4);
our $fdow = (localtime($first))[6];
#printf "1st: %s -> fdow: %s\n",&hdate($first),$fdow;
return $fdow;
}
# -----------------------------------------------------------------------
sub get_shake { # use shake 256 because of ipfs' minimal length of 20Bytes
use Crypt::Digest::SHAKE;
my $len = shift;
local *F; open F,$_[0] or do { warn qq{"$_[0]": $!}; return undef };
#binmode F unless $_[0] =~ m/\.txt/;
my $msg = Crypt::Digest::SHAKE->new(256);
$msg->addfile(*F);
my $digest = $msg->done(($len+7)/8);
return $digest;
}
# -----------------------------------------------------------------------
sub word { # 20^4 * 6^3 words (25bit worth of data ...)
use integer;
my $n = $_[0];
my $vo = [qw ( a e i o u y )]; # 6
my $cs = [qw ( b c d f g h j k l m n p q r s t v w x z )]; # 20
my $str = '';
if (1 && $n < 26) {
$str = chr(ord('a') +$n%26);
} else {
$n -= 6;
while ($n >= 20) {
my $c = $n % 20;
$n /= 20;
$str .= $cs->[$c];
#print "cs: $n -> $c -> $str\n";
$c = $n % 6;
$n /= 6;
$str .= $vo->[$c];
#print "vo: $n -> $c -> $str\n";
}
if ($n > 0) {
$str .= $cs->[$n];
}
return $str;
}
}
# -----------------------------------------------------------------------
1; # $Source: /my/perl/modules/misc.pm $

13
notes.md

@ -0,0 +1,13 @@
# Design Notes
Initial design choices
- protocol/routing/network layer: websockets (multi nonblocking clients)
- server-side fileformat : yaml
- client-side fileformat : JSON
Language choice:
serverside: perl (or nodejs)
clienside: javascript

12
tx.yml

@ -0,0 +1,12 @@
--- # transaction
timestamp: 1623683269225552702
inputs:
- pub1: 50
- pub2: 20
payload: "This is an example of transaction"
outputs:
- pub3: 60
- pubfee: 10
sig:
- pub1: sig1
- pub2: sig2
Loading…
Cancel
Save