Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
mradkov committed Jan 8, 2020
0 parents commit 802c13b
Show file tree
Hide file tree
Showing 43 changed files with 14,883 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
.aeproject-store/
.idea/
dist/
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ISC License

Copyright (c) 2017, aeternity developers

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Tip aggregator / explorer
display tips
16 changes: 16 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
presets: [[
//'@vue/app',
'@babel/preset-env',
{
debug: false,
useBuiltIns: 'usage'
}
]],
plugins: [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-runtime',
'@babel/plugin-transform-block-scoping'
]
}
64 changes: 64 additions & 0 deletions contracts/tip_any_basic.aes
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@compiler >= 4

include "List.aes"
include "Func.aes"
include "Option.aes"

payable contract WaelletTipAnyBasic =

record state =
{ tips : map(string * int, tip)
, tips_flat : map(string, int) }

record tip =
{ sender : address
, received_at : int
, repaid : bool
, amount : int
, note : option(string) }

datatype event =
TipReceived(address, int, string)
| TipWithdrawn(address, int, string)

entrypoint init () : state =
{ tips = {},
tips_flat = {} }

payable stateful entrypoint tip (url: string, note: option(string)) : unit =
put(state{ tips[(url, size(url))] = new_tip(url, note),
tips_flat[url = 0] @ n = n + 1 })
Chain.event(TipReceived(Call.caller, Call.value, url))

entrypoint tips_for_url(url : string) = tips_by_key(url)
entrypoint get_state() : state = state

stateful entrypoint claim(url: string) =
let amount = aggregate_unpaid_tips(url)
do_the_stuff(url, size(url) - 1)
Chain.spend(Call.caller, amount)
Chain.event(TipWithdrawn(Call.caller, amount, url))

stateful function do_the_stuff(url, i) =
if(i < 0) ()
else
put(state{ tips[(url, i)].repaid = true })
do_the_stuff(url, i - 1)

entrypoint unpaid(url : string) =
aggregate_unpaid_tips(url)

function aggregate_unpaid_tips(url : string) =
List.sum(List.map((x) => x.amount, List.filter((x) => x.repaid == false, tips_for_url(url))))

function tips_by_key(key : string) =
[ state.tips[(key, n)] | n <- [0..size(key) - 1] ]

function size(key : string) : int = state.tips_flat[key = 0]

stateful function new_tip(url : string, note: option(string)) : tip =
{ sender = Call.caller,
received_at = Chain.timestamp,
repaid = false,
amount = Call.value,
note = note }
15 changes: 15 additions & 0 deletions deploy-gh-pages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

GIT_REV="$(git rev-parse HEAD)"&& \
rm -rf dist && \
rm -rf node_modules && \
npm install && \
NODE_ENV=prod npm run build && \
cd dist/ && \
git init && \
git remote add origin [email protected]:mradkov/tip-aggregator.git && \
git checkout -b gh-pages && \
git add * && \
git commit -m "tip-aggregator ${GIT_REV} deployment to gh-pages" && \
git fetch && git rebase -s recursive -Xtheirs origin/gh-pages && \
git push origin gh-pages
27 changes: 27 additions & 0 deletions deployment/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* ISC License (ISC)
* Copyright (c) 2018 aeternity developers
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
const Deployer = require('aeproject-lib').Deployer;

const deploy = async (network, privateKey) => {
let deployer = new Deployer(network, privateKey)

let result = await deployer.deploy("./contracts/todo-list.aes")
};

module.exports = {
deploy
};
7 changes: 7 additions & 0 deletions docker-compose.compiler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'
services:
compiler:
hostname: compiler
image: aeternity/aesophia_http:v4.0.0
ports:
- "3080:3080"
61 changes: 61 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Small local network of three nodes using the fastest mean16
version: '3'
services:
node1:
image: aeternity/aeternity:v5.0.2
hostname: node1
environment:
EPOCH_CONFIG: /home/epoch/epoch.yaml
command: >
bin/aeternity console -noinput -aehttp enable_debug_endpoints true
volumes:
- ./docker/aeternity_node1_mean15.yaml:/home/epoch/epoch.yaml
- ./docker/keys/node1:/home/epoch/node/keys
- node1_db:/home/epoch/node/data/mnesia

node2:
image: aeternity/aeternity:v5.0.2
hostname: node2
environment:
EPOCH_CONFIG: /home/epoch/epoch.yaml
command: >
bin/aeternity console -noinput -aehttp enable_debug_endpoints true
volumes:
- ./docker/aeternity_node2_mean15.yaml:/home/epoch/epoch.yaml
- ./docker/keys/node2:/home/epoch/node/keys
- node2_db:/home/epoch/node/data/mnesia

node3:
image: aeternity/aeternity:v5.0.2
hostname: node3
environment:
EPOCH_CONFIG: /home/epoch/epoch.yaml
command: >
bin/aeternity console -noinput -aehttp enable_debug_endpoints true
volumes:
- ./docker/aeternity_node3_mean15.yaml:/home/epoch/epoch.yaml
- ./docker/keys/node3:/home/epoch/node/keys
- node3_db:/home/epoch/node/data/mnesia

proxy:
image: nginx:1.13.8
hostname: proxy
ports:
- "3001:3001"
- "3002:3002"
- "3003:3003"

volumes:
- ./docker/nginx-default.conf:/etc/nginx/conf.d/default.conf
- ./docker/nginx-cors.conf:/etc/nginx/cors.conf
- ./docker/nginx-ws.conf:/etc/nginx/ws.conf



volumes:
node1_db:
node1_keys:
node2_db:
node2_keys:
node3_db:
node3_keys:
48 changes: 48 additions & 0 deletions docker/aeternity_node1_mean15.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
peers:
- aenode://pp_28uQUgsPcsy7TQwnRxhF8GMKU4ykFLKsgf4TwDwPMNaSCXwWV8@node2:3015
- aenode://pp_Dxq41rJN33j26MLqryvh7AnhuZywefWKEPBiiYu2Da2vDWLBq@node3:3015

http:
external:
port: 3013
internal:
debug_endpoints: true
port: 3113
listen_address: 0.0.0.0


websocket:
channel:
listen_address: 0.0.0.0
port: 3014

keys:
peer_password: "top secret"
dir: ./keys

chain:
persist: true
hard_forks:
"1": 0
"2": 1
"3": 2
"4": 3


mining:
autostart: true
beneficiary: "ak_2mwRmUeYmfuW93ti9HMSUJzCk1EYcQEfikVSzgo6k2VghsWhgU"
beneficiary_reward_delay: 2
expected_mine_rate: 4000
micro_block_cycle: 1000
cuckoo:
miner:
executable: mean15-generic
extra_args: ""
edge_bits: 15

fork_management:
network_id: "ae_devnet"


45 changes: 45 additions & 0 deletions docker/aeternity_node2_mean15.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
peers:
- aenode://pp_HdcpgTX2C1aZ5sjGGysFEuup67K9XiFsWqSPJs4RahEcSyF7X@node1:3015
- aenode://pp_Dxq41rJN33j26MLqryvh7AnhuZywefWKEPBiiYu2Da2vDWLBq@node3:3015

http:
external:
port: 3013
internal:
debug_endpoints: true
port: 3113
listen_address: 0.0.0.0


websocket:
channel:
listen_address: 0.0.0.0
port: 3014

keys:
peer_password: "top secret"
dir: ./keys

chain:
persist: true
hard_forks:
"1": 0
"2": 1
"3": 2
"4": 3

mining:
autostart: false
beneficiary: "ak_2mwRmUeYmfuW93ti9HMSUJzCk1EYcQEfikVSzgo6k2VghsWhgU"
beneficiary_reward_delay: 2
expected_mine_rate: 4000
micro_block_cycle: 1000
cuckoo:
miner:
executable: mean15-generic
extra_args: ""
edge_bits: 15

fork_management:
network_id: "ae_devnet"
45 changes: 45 additions & 0 deletions docker/aeternity_node3_mean15.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
peers:
- aenode://pp_HdcpgTX2C1aZ5sjGGysFEuup67K9XiFsWqSPJs4RahEcSyF7X@node1:3015
- aenode://pp_28uQUgsPcsy7TQwnRxhF8GMKU4ykFLKsgf4TwDwPMNaSCXwWV8@node2:3015

http:
external:
port: 3013
internal:
debug_endpoints: true
port: 3113
listen_address: 0.0.0.0


websocket:
channel:
listen_address: 0.0.0.0
port: 3014

keys:
peer_password: "top secret"
dir: ./keys

chain:
persist: true
hard_forks:
"1": 0
"2": 1
"3": 2
"4": 3

mining:
autostart: false
beneficiary: "ak_2mwRmUeYmfuW93ti9HMSUJzCk1EYcQEfikVSzgo6k2VghsWhgU"
beneficiary_reward_delay: 2
expected_mine_rate: 4000
micro_block_cycle: 1000
cuckoo:
miner:
executable: mean15-generic
extra_args: ""
edge_bits: 15

fork_management:
network_id: "ae_devnet"
5 changes: 5 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e

# Using console with extra arguments because "foreground" does not handle SIGTERM/SIGQUIT
exec ./bin/epoch console -noshell -noinput $@
17 changes: 17 additions & 0 deletions docker/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# As this script might be used as docker health check it should exit with either 0/1

EXTERNAL_ADDRESS=${EXTERNAL_ADDRESS:-localhost:3013}
MIN_PEERS=${MIN_PEERS:-2}

curl -s -f -S -o /dev/null --retry 6 http://${EXTERNAL_ADDRESS}/v2/blocks/top || exit 1

if [ -z $INTERNAL_ADDRESS ]; then
exit 0
fi

PEERS_COUNT=$(curl -s -S ${INTERNAL_ADDRESS}/v2/debug/peers | grep -o aenode | wc -l)

# Explicit exit because otherwise test would exit with status 127
test $PEERS_COUNT -ge $MIN_PEERS || exit 1
1 change: 1 addition & 0 deletions docker/keys/beneficiary/key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2�|�[2�1��F�_�衧'm�]�$t'�Za�Ԏ>�1,Bc#��>^aj����tLǕSJ�8�zM�
1 change: 1 addition & 0 deletions docker/keys/beneficiary/key.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�>�1,Bc#��>^aj����tLǕSJ�8�zM�
1 change: 1 addition & 0 deletions docker/keys/node1/peer_key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�(.�G �QR��;l,m�h5� <\��W�5�
1 change: 1 addition & 0 deletions docker/keys/node1/peer_key.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
���G~@>��n�&^F�r�������V�J��
Loading

0 comments on commit 802c13b

Please sign in to comment.