Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
electricity billing stub; testing infrastructure
- Loading branch information
Showing
7 changed files
with
169 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# DONT run directly | ||
|
||
# settings | ||
|
||
EOS_DIR="$HOME/eos-hackathon" | ||
EOS_NETWORK="hackathon" | ||
EOS_DOCKER='docker' | ||
|
||
|
||
# computed - dont touch | ||
|
||
NODEOS_DATA="$EOS_DIR/nodeos" | ||
KEOSD_DATA="$EOS_DIR/keosd" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu | ||
set -o pipefail | ||
|
||
BIN_DIR="$(cd $(dirname $0) && pwd)" | ||
|
||
. "$BIN_DIR/_local_chain.incl.sh" | ||
|
||
|
||
set -x | ||
|
||
$EOS_DOCKER run --rm --network "$EOS_NETWORK" \ | ||
eosio/eos-dev /opt/eosio/bin/cleos \ | ||
-u http://nodeos:8888/ \ | ||
--wallet-url http://keosd:8888/ \ | ||
"$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Removes data of test single-node network | ||
# | ||
|
||
set -eu | ||
set -o pipefail | ||
|
||
BIN_DIR="$(cd $(dirname $0) && pwd)" | ||
|
||
. "$BIN_DIR/_local_chain.incl.sh" | ||
|
||
|
||
"$BIN_DIR/stop_local_chain.sh" &>/dev/null || true | ||
|
||
|
||
rm -rf "$EOS_DIR" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Starts test single-node network | ||
# | ||
|
||
set -eu | ||
set -o pipefail | ||
|
||
BIN_DIR="$(cd $(dirname $0) && pwd)" | ||
|
||
. "$BIN_DIR/_local_chain.incl.sh" | ||
|
||
|
||
mkdir -p "$EOS_DIR" | ||
mkdir -p "$NODEOS_DATA" | ||
mkdir -p "$KEOSD_DATA" | ||
|
||
|
||
set -x | ||
|
||
$EOS_DOCKER network create "$EOS_NETWORK" | ||
|
||
$EOS_DOCKER run --rm -d --network "$EOS_NETWORK" --name nodeos -v "$NODEOS_DATA":/data \ | ||
eosio/eos-dev /opt/eosio/bin/nodeos \ | ||
-d /data \ | ||
--http-server-address=0.0.0.0:8888 \ | ||
-e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin | ||
|
||
$EOS_DOCKER run --rm -d --network "$EOS_NETWORK" --name keosd -v "$KEOSD_DATA":/data \ | ||
eosio/eos-dev /opt/eosio/bin/keosd \ | ||
-d /data \ | ||
--http-server-address=0.0.0.0:8888 \ | ||
|
||
set +x | ||
|
||
|
||
sleep 2 | ||
|
||
EOS_KEY=$("$BIN_DIR/cleos" create key | perl -ne 'print $1 if /^Private key:\s+([^\s]+)/') | ||
|
||
|
||
echo OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Stops test single-node network | ||
# | ||
|
||
set -eu | ||
set -o pipefail | ||
|
||
BIN_DIR="$(cd $(dirname $0) && pwd)" | ||
|
||
. "$BIN_DIR/_local_chain.incl.sh" | ||
|
||
|
||
set -x | ||
|
||
|
||
$EOS_DOCKER stop keosd || true | ||
$EOS_DOCKER stop nodeos || true | ||
|
||
$EOS_DOCKER network rm "$EOS_NETWORK" || true | ||
|
||
|
||
set +x | ||
|
||
echo OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// Created by Eenae on 09.06.2018. | ||
// | ||
|
||
#include <eosiolib/eosio.hpp> | ||
#include <eosiolib/asset.hpp> | ||
#include <eosiolib/currency.hpp> | ||
|
||
#include <string> | ||
#include <sstream> | ||
#include <algorithm> | ||
#include <iterator> | ||
|
||
#include "billing.hpp" | ||
|
||
using eosio::asset; | ||
using eosio::const_mem_fun; | ||
using eosio::indexed_by; | ||
using std::string; | ||
using std::istringstream; | ||
|
||
|
||
class billing_electricity : /*public billing,*/ public eosio::contract { | ||
public: | ||
billing_electricity(account_name self) : | ||
contract(self) {} | ||
|
||
// @abi action | ||
void bill(uint64_t device_data, account_name user2bill, string user_meta, string billing_meta) { | ||
// device_data is a number of measurements sent | ||
// billing_meta: <float: watts/hour per measurement>\t<uint: payment per kWt/hour> | ||
|
||
istringstream iss(billing_meta); | ||
|
||
float wattPerMeasurement; | ||
iss >> wattPerMeasurement; | ||
|
||
uint64_t paymentPerKWT; | ||
iss >> paymentPerKWT; | ||
|
||
eosio::print( "wattPerMeasurement = ", wattPerMeasurement, " paymentPerKWT = ", paymentPerKWT, "\n" ); | ||
} | ||
}; | ||
|
||
EOSIO_ABI( billing_electricity, (bill) ) | ||
|
||
|
||
int main(int argc, char **argv) { | ||
billing_electricity(N("self")).bill(1U, N("foo"), string(), string("0.3125 2")); | ||
|
||
return 0; | ||
} | ||
|