Skip to content

Commit

Permalink
initial scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
disassembler committed Oct 16, 2020
1 parent 59f9945 commit 2ea7b30
Show file tree
Hide file tree
Showing 8 changed files with 534 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
secrets/
/.terraform
/config.tf.json
*.sk
*.pk
*.skey
*.vkey
*.txbody
*.txsigned
*.sig
state*
30 changes: 30 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Catalyst Voting Tools

# Vote Registration

To register to vote, a ed25519extended key needs generated with jcli and a stake secret key and payment secret key need to be provided.

Usage:

```
nix-shell
jcli key generate --type ed25519extended > vote.sk
jcli key to-public < vote.sk > vote.pk
python vote-registration.py --payment-signing-key payment.skey --payment-address addr_test1vrd26p8d9dlknc4fhevzudcfzuul5qm2znquytugqcw583czzqrpm --vote-public-key vote.pk --stake-signing-key stake.skey
```

# Voter Key and Stake Export

To export voter the voter key and associated stake, cardano-db-sync is required.

```
nix-shell
python fetch.py
```

# Generate QR code for Catalyst

```
nix-shell
vit-kedqr -pin 1234 -input vote.sk
```
25 changes: 25 additions & 0 deletions scripts/fetch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import binascii
import cbor2
import json
import subprocess
from vitlib import VITBridge
from cardanolib import CardanoCLIWrapper

bridge = VITBridge(1097911063, "/home/sam/work/iohk/cardano-node/master/state-node-testnet", "cexplorer", "cexplorer", "/run/postgresql")
cardano = CardanoCLIWrapper(1097911063, "/home/sam/work/iohk/cardano-node/master/state-node-testnet")

vote_stake = {}

keys = bridge.fetch_voting_keys()
for key,value in keys.items():
stake = bridge.get_stake(key)
if value in vote_stake:
vote_stake[value] += stake
else:
vote_stake[value] = stake

initial_funds = []
for key, value in vote_stake.items():
initial_funds.append({"address": key, "value": value})

print(json.dumps(initial_funds))
74 changes: 74 additions & 0 deletions scripts/nix/sources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"cardano-node": {
"branch": "cardano-lib-metadata",
"description": "The core component that is used to participate in a Cardano decentralised blockchain.",
"homepage": "https://cardano.org",
"owner": "input-output-hk",
"repo": "cardano-node",
"rev": "5af4d86aa36241cba8914c9827c72f8b7caf152a",
"sha256": "17xh743dip3igym07my0zyy1a5xn2wf09jh6drzhqmb4aagfi96x",
"type": "tarball",
"url": "https://github.com/input-output-hk/cardano-node/archive/5af4d86aa36241cba8914c9827c72f8b7caf152a.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"cardano-wallet": {
"branch": "master",
"description": "HTTP server & command-line for managing UTxOs and HD wallets in Cardano.",
"homepage": "",
"owner": "input-output-hk",
"repo": "cardano-wallet",
"rev": "ac9e1d0b04d901eec6904d5951e81fac50150357",
"sha256": "00p7d8gm3k8x200mwf0jnnyssrpzapwxk8hwmsp6a48g1sfh32n1",
"type": "tarball",
"url": "https://github.com/input-output-hk/cardano-wallet/archive/ac9e1d0b04d901eec6904d5951e81fac50150357.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"iohk-nix": {
"branch": "master",
"description": "nix scripts shared across projects",
"homepage": null,
"owner": "input-output-hk",
"repo": "iohk-nix",
"rev": "f345d26508966e434d8db57d6c3b4ce4202c9fb5",
"sha256": "1xcar2r6jm68dp5s8kc2rii0rcg47w41qc1akazbngkj1x6hf1r2",
"type": "tarball",
"url": "https://github.com/input-output-hk/iohk-nix/archive/f345d26508966e434d8db57d6c3b4ce4202c9fb5.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"niv": {
"branch": "master",
"description": "Easy dependency management for Nix projects",
"homepage": "https://github.com/nmattia/niv",
"owner": "nmattia",
"repo": "niv",
"rev": "ab9cc41caf44d1f1d465d8028e4bc0096fd73238",
"sha256": "17k52n8zwp832cqifsc4458mhy4044wmk22f807171hf6p7l4xvr",
"type": "tarball",
"url": "https://github.com/nmattia/niv/archive/ab9cc41caf44d1f1d465d8028e4bc0096fd73238.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
"branch": "nixos-20.03",
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
"homepage": "https://github.com/NixOS/nixpkgs",
"owner": "NixOS",
"repo": "nixpkgs-channels",
"rev": "c9f5211b769a2edc46037cafcdf4e15b694820d6",
"sha256": "1qra1lrj3chmyrxmybaqgidp562wcss69461svwx8mzhli50xq5c",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs-channels/archive/c9f5211b769a2edc46037cafcdf4e15b694820d6.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"vit-kedqr": {
"branch": "nix-build",
"description": null,
"homepage": null,
"owner": "input-output-hk",
"repo": "vit-kedqr",
"rev": "e6846fd3a25e9cd65b365a6287ea21c63517146f",
"sha256": "0qgk9haxbclvz9r6pzkggdxv9rdymm1k0vqksfqmqkylq4r44b5k",
"type": "tarball",
"url": "https://github.com/input-output-hk/vit-kedqr/archive/e6846fd3a25e9cd65b365a6287ea21c63517146f.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
134 changes: 134 additions & 0 deletions scripts/nix/sources.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# This file has been generated by Niv.

let

#
# The fetchers. fetch_<type> fetches specs of type <type>.
#

fetch_file = pkgs: spec:
if spec.builtin or true then
builtins_fetchurl { inherit (spec) url sha256; }
else
pkgs.fetchurl { inherit (spec) url sha256; };

fetch_tarball = pkgs: spec:
if spec.builtin or true then
builtins_fetchTarball { inherit (spec) url sha256; }
else
pkgs.fetchzip { inherit (spec) url sha256; };

fetch_git = spec:
builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };

fetch_builtin-tarball = spec:
builtins.trace
''
WARNING:
The niv type "builtin-tarball" will soon be deprecated. You should
instead use `builtin = true`.
$ niv modify <package> -a type=tarball -a builtin=true
''
builtins_fetchTarball { inherit (spec) url sha256; };

fetch_builtin-url = spec:
builtins.trace
''
WARNING:
The niv type "builtin-url" will soon be deprecated. You should
instead use `builtin = true`.
$ niv modify <package> -a type=file -a builtin=true
''
(builtins_fetchurl { inherit (spec) url sha256; });

#
# Various helpers
#

# The set of packages used when specs are fetched using non-builtins.
mkPkgs = sources:
let
sourcesNixpkgs =
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {};
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
in
if builtins.hasAttr "nixpkgs" sources
then sourcesNixpkgs
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
import <nixpkgs> {}
else
abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json.
'';

# The actual fetching function.
fetch = pkgs: name: spec:

if ! builtins.hasAttr "type" spec then
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
else if spec.type == "file" then fetch_file pkgs spec
else if spec.type == "tarball" then fetch_tarball pkgs spec
else if spec.type == "git" then fetch_git spec
else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec
else if spec.type == "builtin-url" then fetch_builtin-url spec
else
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";

# Ports of functions for older nix versions

# a Nix version of mapAttrs if the built-in doesn't exist
mapAttrs = builtins.mapAttrs or (
f: set: with builtins;
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
);

# fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball = { url, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12" then
fetchTarball { inherit url; }
else
fetchTarball attrs;

# fetchurl version that is compatible between all the versions of Nix
builtins_fetchurl = { url, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchurl;
in
if lessThan nixVersion "1.12" then
fetchurl { inherit url; }
else
fetchurl attrs;

# Create the final "sources" from the config
mkSources = config:
mapAttrs (
name: spec:
if builtins.hasAttr "outPath" spec
then abort
"The values in sources.json should not have an 'outPath' attribute"
else
spec // { outPath = fetch config.pkgs name spec; }
) config.sources;

# The "config" used by the fetchers
mkConfig =
{ sourcesFile ? ./sources.json
, sources ? builtins.fromJSON (builtins.readFile sourcesFile)
, pkgs ? mkPkgs sources
}: rec {
# The sources, i.e. the attribute set of spec name to spec
inherit sources;

# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
inherit pkgs;
};
in
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
36 changes: 36 additions & 0 deletions scripts/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
let
sources = import ./nix/sources.nix {};
pkgs = import sources.nixpkgs {};

src = pkgs.fetchurl {
url = "https://github.com/input-output-hk/jormungandr/releases/download/v0.9.3/jormungandr-0.9.3-x86_64-unknown-linux-musl-generic.tar.gz";
sha256 = "sha256:14giz9yz94mdjrdr96rz5xsj21aacdw8mqrfdz031czh4qgnmnzh";
};
jormungandr = pkgs.runCommand "jormungandr" { buildInputs = [ pkgs.gnutar ]; } ''
mkdir -p $out/bin
cd $out/bin
tar -zxvf ${src}
'';
cardanolib-py = (import (sources.cardano-node + "/nix") { gitrev = sources.cardano-node.rev;}).cardanolib-py;
cardano-node-nix = import (sources.cardano-node) { gitrev = sources.cardano-node.rev;};
bech32 = cardano-node-nix.bech32;
cardano-cli = cardano-node-nix.cardano-cli;
vit-kedqr = import sources.vit-kedqr {};
in pkgs.stdenv.mkDerivation {
name = "vit-meta-shell";
buildInputs = [
jormungandr
cardano-cli
bech32
pkgs.python3Packages.ipython
pkgs.python3Packages.cbor2
pkgs.python3Packages.docopt
pkgs.python3Packages.psycopg2
cardanolib-py
vit-kedqr
];
shellHook = ''
export CARDANO_NODE_SOCKET_PATH=/home/sam/work/iohk/cardano-node/master/state-node-testnet/node.socket
source <(cardano-cli --bash-completion-script cardano-cli)
'';
}
Loading

0 comments on commit 2ea7b30

Please sign in to comment.