Skip to content

Commit

Permalink
make user interface for dice nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
zack-bitcoin committed Feb 9, 2017
1 parent cacd0dc commit 7551ed8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
24 changes: 6 additions & 18 deletions src/channels/channel_feeder.erl
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ handle_call({agree_simplification, Name, SSPK, OtherSS}, _From, X) ->
SPK = testnet_sign:data(SSPK),
Other = other(SPK),
{Return, _OurSecret} = make_simplification_internal(Other, Name, OtherSS),
io:fwrite("agree simplifications "),
io:fwrite(packer:pack(SSPK)),
io:fwrite("\n"),
update_to_me_internal(Return, SSPK),
{reply, Return, X};
handle_call(_, _From, X) -> {reply, X, X}.
Expand All @@ -157,37 +154,28 @@ update_to_me_internal(OurSPK, SSPK) ->
Other = other(SPK),
{ok, OldCD} = channel_manager:read(Other),
NewCD = OldCD#cd{them = SSPK, ssthem = OldCD#cd.ssme},
io:fwrite("update to me internal!!!!\n"),
channel_manager:write(Other, NewCD).

make_simplification_internal(Other, dice, OtherSS) ->
%currently Secret is the 12 byte secret. It should be their ScriptSig.
%calculate who won the dice game, give them the money.
%1=0,
{ok, OldCD} = channel_manager:read(Other),
true = OldCD#cd.live,
Them = OldCD#cd.them,

SPK = testnet_sign:data(Them),
Acc1 = spk:acc1(SPK),
Acc2 = spk:acc2(SPK),
{Accounts, Channels,_,_} = tx_pool:data(),
%io:fwrite("Secret is "),
%io:fwrite(Secret),
%io:fwrite("\n"),%secret is their script sig.
{Amount, _Nonce, _SS, OurSecret} = channel_solo_close:next_ss(Other, OtherSS, SPK, Acc1, Acc2, Accounts, Channels),

NewSPK = spk:settle_bet(SPK, [], Amount),

NewCD = OldCD#cd{me = NewSPK, ssme = []},
channel_manager:write(Other, NewCD),
{keys:sign(NewSPK, Accounts), OurSecret}.%we should also return our secret.

make_bet_internal(Other, dice, Vars, Secret) ->%this should only be called by the channel_feeder gen_server, because it updates the channel_manager.
%SSme = dice:make_ss(SPK, Secret),
io:fwrite("channel feeder make_bet_internal. other is "),
io:fwrite(integer_to_list(Other)),
io:fwrite("\n"),
%io:fwrite("channel feeder make_bet_internal. other is "),
%io:fwrite(integer_to_list(Other)),
%io:fwrite("\n"),
{ok, OldCD} = channel_manager:read(Other),
true = OldCD#cd.live,
Them = OldCD#cd.them,
Expand Down Expand Up @@ -282,7 +270,7 @@ depth_check2(SPK, C, OldC) ->
end.

get_bet(Name, [{Name, Loc}|_], Vars, SPK) ->
io:fwrite("get_bets"),
%io:fwrite("get_bets"),
get_bet2(Name, Loc, Vars, SPK);
get_bet(Name, [_|T], Vars, SPK) -> get_bet(Name, T, Vars, SPK).
get_bet2(dice, Loc, [Amount, Commit1, Commit2], SPK) ->
Expand All @@ -303,8 +291,8 @@ get_bet2(dice, Loc, [Amount, Commit1, Commit2], SPK) ->
macro Commit1 binary " ++ integer_to_list(size(Commit1))++" "++ binary_to_list(base64:encode(Commit1)) ++ " ; \n
macro Commit2 binary " ++ integer_to_list(size(Commit2))++ " " ++ binary_to_list(base64:encode(Commit2)) ++ " ; \n
",
io:fwrite("channel feeder front is \n"),
io:fwrite(Front),
%io:fwrite("channel feeder front is \n"),
%io:fwrite(Front),
Bet = compile:doit(Loc, Front),
[] = spk:bets(SPK),%for now we only make 1 bet per customer at a time, otherwise it would be possible for a customer to make us check their complicated script over and over on each bet, to see if it can close any of them.
spk:apply_bet(Bet, SPK, 1000, 1000).
Expand Down
12 changes: 6 additions & 6 deletions src/consensus/txs/channel_solo_close.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ check_slash(From, Acc1, Acc2, TheirSS, SSPK, Accounts, Channels, TheirNonce) ->
next_ss(From, TheirSS, SPK, Acc1, Acc2, Accounts, Channels) ->
%this is customized for dice.
{ok, CD} = channel_manager:read(From),
io:fwrite("in next_ss. CD is "),
io:fwrite(packer:pack(CD)),
io:fwrite("\n"),
%io:fwrite("in next_ss. CD is "),
%io:fwrite(packer:pack(CD)),
%io:fwrite("\n"),
OurSS1 = channel_feeder:script_sig_them(CD),%this is not a typo. this is OurSS which can be used for the highest nonced SPK they signed before this SPK we are currently looking at.
OurSS = case OurSS1 of%this trick only works because we limit it to one bet per channel.
[] -> channel_feeder:script_sig_me(CD);
Expand Down Expand Up @@ -106,9 +106,9 @@ next_ss(From, TheirSS, SPK, Acc1, Acc2, Accounts, Channels) ->
SSF = <<2, S1size:32, S1/binary, 2, S2size:32, S2/binary, 0, 3:32>>,

{Amount2, Nonce2} = spk:run(safe, [SSF], SPK, NewHeight, Slash, Accounts, Channels),
io:fwrite("channel solo close nonce "),
io:fwrite(integer_to_list(Nonce2)),
io:fwrite("\n"),
%io:fwrite("channel solo close nonce "),
%io:fwrite(integer_to_list(Nonce2)),
%io:fwrite("\n"),
NonceM = max(Nonce1, Nonce2),
case NonceM of
Nonce1 -> Out1;
Expand Down
1 change: 1 addition & 0 deletions src/easy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ integer_channel_balance() ->
{_, Channel, _} = channel:get(CID, Channels),
channel:bal1(Channel)-Amount.
dice(Amount) ->
unlocked = keys:status(),
A = to_int(Amount),
internal_handler:doit({dice, A, constants:server_ip(), constants:server_port()}).
close_channel() ->
Expand Down

0 comments on commit 7551ed8

Please sign in to comment.