Skip to content

Commit

Permalink
Clone of old hschain project as start for PoW
Browse files Browse the repository at this point in the history
  • Loading branch information
thesz committed Jun 11, 2020
1 parent 66d757d commit 59a72c0
Show file tree
Hide file tree
Showing 14 changed files with 358 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hschain-utxo-pow-node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for hschain-utxo

## 0.1.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
30 changes: 30 additions & 0 deletions hschain-utxo-pow-node/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Author name here (c) 2018

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions hschain-utxo-pow-node/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
54 changes: 54 additions & 0 deletions hschain-utxo-pow-node/app/Genesis.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- | Generates initial genesis with all funds owned by single user.
module Main where

import Data.Aeson.Encode.Pretty
import Data.Aeson
import Data.Default
import Data.Fix

import Hschain.Utxo.Lang
import Hschain.Utxo.Lang.Build

import Data.ByteString.Char8 as B
import Data.ByteString.Lazy as LB
import Data.ByteString.Char8 as LB
import qualified Data.Map.Strict as M
import qualified Data.Vector as V

main :: IO ()
main = B.putStrLn . LB.toStrict . encodePretty =<< singleOwnerGenesis

singleOwnerGenesis :: IO [Tx]
singleOwnerGenesis = withSecret =<< newSecret
where
withSecret secret = do
Right proof <- newProof env (Fix $ SigmaPk publicKey)
return $ [tx proof]
where
publicKey = getPublicKey secret
env = proofEnvFromKeys [getKeyPair secret]

box = Box
{ box'id = BoxId "master:box-0"
, box'value = initMoney
, box'script = toScript $ pk' publicKey
, box'args = M.empty
}

tx proof = Tx
{ tx'inputs = V.empty
, tx'outputs = V.fromList [box]
, tx'proof = Just proof
, tx'args = mempty
}

initMoney = 1000000









7 changes: 7 additions & 0 deletions hschain-utxo-pow-node/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Main where

import Hschain.Utxo.App

main :: IO ()
main = runApp

20 changes: 20 additions & 0 deletions hschain-utxo-pow-node/config/main/node-val1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
port : "45001"
seeds :
- "127.0.0.1:45002"
- "127.0.0.1:45003"
- "127.0.0.1:45004"
privKey : "2K7bFuJXxKf5LqogvVRQjms2W26ZrjpvUjo5LdvPFa5Y"
validators:
- "HVQNfbH8rj2uVb6XyC41wzGCMGVFooeBZJMLnRBJifTX"
- "HUs35FXTSYA3zY39MrKjqFdeCvTxx97uccPFxvwpqgt7"
- "AZ3m8VUkPJ8iGNgQ5zpG4rMBqg5VNAYtSaJDmrR4Rz1m"
- "2PggMrWVjsvUvrZHqYVgH4PRpjVp2oYJe9gjaWrU1R4m"
dbName : "/var/run/user/1000/db/node-1"
logs:
files :
- type : "ScribeJSON"
path : "logs/node-1.log"
severity : "Debug"
verbosity : "V2"
namespace: "validator-node1"

19 changes: 19 additions & 0 deletions hschain-utxo-pow-node/config/main/node-val2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
port : "45002"
seeds :
- "127.0.0.1:45003"
- "127.0.0.1:45004"
privKey : "4NSWtMsEPgfTK25tCPWqNzVVze1dgMwcUFwS5WkSpjJL"
validators:
- "HVQNfbH8rj2uVb6XyC41wzGCMGVFooeBZJMLnRBJifTX"
- "HUs35FXTSYA3zY39MrKjqFdeCvTxx97uccPFxvwpqgt7"
- "AZ3m8VUkPJ8iGNgQ5zpG4rMBqg5VNAYtSaJDmrR4Rz1m"
- "2PggMrWVjsvUvrZHqYVgH4PRpjVp2oYJe9gjaWrU1R4m"
dbName : "/var/run/user/1000/db/node-2"
logs:
files :
- type : "ScribeJSON"
path : "logs/node-2.log"
severity : "Debug"
verbosity : "V2"
namespace: "validator-node2"

18 changes: 18 additions & 0 deletions hschain-utxo-pow-node/config/main/node-val3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
port : "45003"
seeds :
- "127.0.0.1:45004"
privKey : "3Fj8bZjKc53F2a87sQaFkrDas2d9gjzK57FmQwnNnSHS"
validators:
- "HVQNfbH8rj2uVb6XyC41wzGCMGVFooeBZJMLnRBJifTX"
- "HUs35FXTSYA3zY39MrKjqFdeCvTxx97uccPFxvwpqgt7"
- "AZ3m8VUkPJ8iGNgQ5zpG4rMBqg5VNAYtSaJDmrR4Rz1m"
- "2PggMrWVjsvUvrZHqYVgH4PRpjVp2oYJe9gjaWrU1R4m"
dbName : "/var/run/user/1000/db/node-3"
logs:
files :
- type : "ScribeJSON"
path : "logs/node-3.log"
severity : "Debug"
verbosity : "V2"
namespace: "validator-node3"

17 changes: 17 additions & 0 deletions hschain-utxo-pow-node/config/main/node-val4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
port : "45004"
seeds : []
privKey : "D2fpHM1JA8trshiUW8XPvspsapUvPqVzSofaK1MGRySd"
validators:
#- "HVQNfbH8rj2uVb6XyC41wzGCMGVFooeBZJMLnRBJifTX"
# - "HUs35FXTSYA3zY39MrKjqFdeCvTxx97uccPFxvwpqgt7"
# - "AZ3m8VUkPJ8iGNgQ5zpG4rMBqg5VNAYtSaJDmrR4Rz1m"
- "2PggMrWVjsvUvrZHqYVgH4PRpjVp2oYJe9gjaWrU1R4m"
dbName : "/var/run/user/1000/db/node-4"
logs:
files :
- type : "ScribeJSON"
path : "logs/node-4.log"
severity : "Debug"
verbosity : "V2"
namespace: "validator-node4"

23 changes: 23 additions & 0 deletions hschain-utxo-pow-node/config/main/node-web.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
server:
host: 127.0.0.1
port: 8080
node:
port: "45000"
seeds:
- "127.0.0.1:45001"
- "127.0.0.1:45002"
- "127.0.0.1:45003"
- "127.0.0.1:45004"
validators:
- "HVQNfbH8rj2uVb6XyC41wzGCMGVFooeBZJMLnRBJifTX"
- "HUs35FXTSYA3zY39MrKjqFdeCvTxx97uccPFxvwpqgt7"
- "AZ3m8VUkPJ8iGNgQ5zpG4rMBqg5VNAYtSaJDmrR4Rz1m"
- "2PggMrWVjsvUvrZHqYVgH4PRpjVp2oYJe9gjaWrU1R4m"
dbName : "/var/run/user/1000/db/node-web"
logs:
files :
- type : "ScribeJSON"
severity : "Debug"
path : "logs/node-web.log"
verbosity : "V2"
namespace: "node-web"
14 changes: 14 additions & 0 deletions hschain-utxo-pow-node/config/pool/genesis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"args": {},
"inputs": [],
"outputs": [
{
"script": "pk \"2zYxFt1frN27gKPHoQNfEHt5e7AqSUkLQ5kZ1b9a2cPxWzV\"",
"args": {},
"value": 1000000,
"id": "master:box-0"
}
]
}
]
68 changes: 68 additions & 0 deletions hschain-utxo-pow-node/hschain-utxo-pow-node.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
cabal-version: >=1.10
name: hschain-utxo
version: 0.1.0.0
synopsis: Useful utils for hschain-utxo (generation of genesis)
-- description:
-- bug-reports:
-- license:
license-file: LICENSE
author: anton-k
maintainer: [email protected]
-- copyright:
-- category:
build-type: Simple
extra-source-files: CHANGELOG.md

library
exposed-modules: Hschain.Utxo.App
Hschain.Utxo.App.Options
-- other-modules:
-- other-extensions:
build-depends: base >=4.11 && <5
, hex-common
, hschain-utxo-lang
, hschain-utxo-service
, optparse-applicative
hs-source-dirs: src
default-language: Haskell2010
default-extensions:
DataKinds
DeriveGeneric
GeneralizedNewtypeDeriving
LambdaCase
MultiParamTypeClasses
TypeFamilies
OverloadedStrings
RecordWildCards
ScopedTypeVariables
StandaloneDeriving
TemplateHaskell


executable hschain-utxo-pow-node-app
main-is: Main.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.11 && <5
, hschain-utxo
hs-source-dirs: app
default-language: Haskell2010

executable hschain-utxo-pow-generate-genesis
main-is: Genesis.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.11 && <5
, aeson
, aeson-pretty
, bytestring
, containers
, data-default
, data-fix
, hschain-utxo-lang
, vector
hs-source-dirs: app
default-language: Haskell2010
default-extensions:
OverloadedStrings

33 changes: 33 additions & 0 deletions hschain-utxo-pow-node/src/Hschain/Utxo/App.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Hschain.Utxo.App(
runApp
) where

import Hex.Common.Aeson
import Hex.Common.Yaml

import Control.Monad

import Data.Maybe

import Hschain.Utxo.Lang
import Hschain.Utxo.Back.App
import Hschain.Utxo.App.Options

runApp :: IO ()
runApp = app =<< readOptions

app :: Options -> IO ()
app = \case
RunWebNode{..} -> runBy runWebNode runWebNode'config runWebNode'genesis
RunValidator{..} -> runBy runValidator runValidator'config runValidator'genesis
where
runBy :: (FromJSON a, Show a) => (a -> [Tx] -> IO ()) -> FilePath -> FilePath -> IO ()
runBy cmd configPath genesisPath =
join $ cmd <$> readYaml configPath <*> readGenesis genesisPath

readGenesis :: FilePath -> IO [Tx]
readGenesis = fmap (fromMaybe err) . readJson
where
err = error "Error: failed to read genesis"


48 changes: 48 additions & 0 deletions hschain-utxo-pow-node/src/Hschain/Utxo/App/Options.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module Hschain.Utxo.App.Options(
Options(..)
, readOptions
) where

import Options.Applicative

readOptions :: IO Options
readOptions = execParser opts
where
opts = info (options <**> helper)
( fullDesc
<> progDesc "Utility to run webnodes and validators"
<> header "hschain-utxo - utility to run webnodes and validators" )

data Options
= RunWebNode
{ runWebNode'config :: FilePath
, runWebNode'genesis :: FilePath
}
| RunValidator
{ runValidator'config :: FilePath
, runValidator'genesis :: FilePath
}

options :: Parser Options
options = subparser
( command "webnode" webnodeParser
<> command "validator" validatorParser
)
where
webnodeParser = configParser RunWebNode "Run webnode"
validatorParser = configParser RunValidator "Run validator"

configParser cons msg = info parser (progDesc msg)
where
parser = cons
<$> strOption
( metavar "CONFIG_FILE_PATH"
<> long "config"
<> short 'c'
<> help "path to config")
<*> strOption
( metavar "GENESIS_FILE_PATH"
<> long "genesis"
<> short 'g'
<> help "path to genesis")

0 comments on commit 59a72c0

Please sign in to comment.