Skip to content

Commit

Permalink
Updating: more responsive interface
Browse files Browse the repository at this point in the history
  • Loading branch information
gallettilance committed Apr 25, 2018
1 parent ec0b201 commit 1a0cc75
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/block_ops.dats
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ file_write_block(e: block): void
implement
mine(hd) = let
val (ind, nonce, trns, code, h) = hd
val theValids = list0_filter(trns, lam(t) => is_valid_transact(t))
val temp = list0_filter(trns, lam(t) => is_valid_transact(t))
val theValids = list0_filter(temp, lam(t) => make_transact(t))

fun aux(hd: header): block = let
val currh = sha256(encode_header(hd))
Expand Down
16 changes: 13 additions & 3 deletions src/cli.dats
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ case+ args of
then let val coins = get_coins(a) in println!("Balance of ", a, " is ", coins) end
else println!("unrecognized miner")


implement
do_execute(args) =
case+ args of
Expand All @@ -138,6 +139,7 @@ in
file_write_contract((f, val2str(interp(parse_lisp(f)))))
end


implement
do_transact(args) =
case+ args of
Expand All @@ -152,15 +154,23 @@ case+ args of
let val trns = (a, b, string2int(c))
in transact(trns) end


implement
do_mine(args) =
case+ args of
| nil0() => (println!("must provide <miner> argument"); ())
| cons0(a, _) => let
val test = is_miner(a)
val test_miner = is_miner(a)
val test_transact = list0_length(list0_filter(get_data(), lam(t) => is_valid_transact(t))) > 0
val test_code = list0_length(get_result()) > 0
val test = test_miner andalso test_transact andalso test_code
in
if test then (chain_add(); reward(a); clear_transact())
else (println!("unrecognized miner - please define miner first"); ())
ifcase
| test => (chain_add(); reward(a); clear_transact())
| ~test_miner => (println!("unrecognized miner - please define miner first"); ())
| ~test_transact => (println!("must have at least one valid transaction per block"); ())
| ~test_code => (println!("must have at least one smart contract per block"); ())
| _ => (println!("True = False?"); ())
end


Expand Down
29 changes: 29 additions & 0 deletions src/trans_ops.dats
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ extern
fun
is_valid_transact(t: transaction): bool

extern
fun
make_transact(t: transaction): bool //same as is_valid_transact with necessary side effect

extern
fun
get_data(): data
Expand Down Expand Up @@ -142,6 +146,30 @@ is_valid_transact(t) = let
val receiver = t.1
val amount = t.2
val test_exists = is_miner(sender) andalso is_miner(receiver)
in
if test_exists
then
(
let
val sender_balance = get_coins(sender)
val receiver_balance = get_coins(receiver)
val test_balance = sender_balance >= amount
in
if test_balance
then true
else false
end
)
else false
end


implement
make_transact(t) = let
val sender = t.0
val receiver = t.1
val amount = t.2
val test_exists = is_miner(sender) andalso is_miner(receiver)
in
if test_exists
then
Expand Down Expand Up @@ -170,6 +198,7 @@ get_data() = let
val ft = fileref_open_opt("./transaction.txt", file_mode_r)
in
case- ft of
| ~None_vt() => nil0()
| ~Some_vt(trns) => let
val theLines = streamize_fileref_line(trns)
in
Expand Down

0 comments on commit 1a0cc75

Please sign in to comment.