coase contracts in new ligo

This commit is contained in:
Galfour 2019-05-05 22:50:37 +00:00
parent 5ae00aeb01
commit a2caec9939
3 changed files with 25 additions and 3 deletions

View File

@ -10,7 +10,8 @@ type card_patterns is map(card_pattern_id , card_pattern)
type card_id is nat
type card is record [
card_owner : address
card_owner : address ;
card_pattern : card_pattern_id ;
]
type cards is map(card_id , card)
@ -33,9 +34,27 @@ type action_transfer is record [
type action is
| Buy_single of action_buy_single
// | Sell of action_sell
// | Sell of action_sell_single
// | Transfer of action_transfer
// function sell_single(const action : action_sell_single ; const s : storage_type) : (list(operation) * storage_type) is
// begin
// const card : card = get_force(action.card_to_sell , s.cards) ;
// if (card.card_owner =/= source) then fail "This card doesn't belong to you" else skip ;
// const card_pattern : card_pattern = get_force(card.card_pattern , s.card_patterns) ;
// card_pattern.quantity := abs(card_pattern.quantity - 1n);
// const card_patterns : card_patterns = s.card_patterns ;
// card_patterns[card.card_pattern] := card_pattern ;
// s.card_patterns := card_patterns ;
// const cards : cards = s.cards ;
// remove action.card_to_sell from map cards ;
// s.cards := cards ;
// const price : tez = card_pattern.coefficient * card_pattern.quantity ;
// const receiver : contract(unit) = get_contract(source) ;
// const op : operation = transaction(price , unit , receiver) ;
// const operations : list(operation) = list op end ;
// end with (operations , s)
function buy_single(const action : action_buy_single ; const s : storage_type) : (list(operation) * storage_type) is
begin
// Check funds
@ -53,6 +72,7 @@ function buy_single(const action : action_buy_single ; const s : storage_type) :
const cards : cards = s.cards ;
cards[s.next_id] := record
card_owner = source ;
card_pattern = action.card_to_buy ;
end ;
s.cards := cards ;
s.next_id := s.next_id + 1n ;

View File

@ -19,10 +19,12 @@ open Ast_simplified
let card owner =
ez_e_a_record [
("card_owner" , owner) ;
("card_pattern" , e_a_nat 0) ;
]
let card_ty = t_record_ez [
("card_owner" , t_address) ;
("card_pattern" , t_nat) ;
]
let card_ez owner = card (e_a_address owner)

View File

@ -28,7 +28,7 @@ let expect ?(options = make_options ()) program entry_point input expected =
let content () = Format.asprintf "Entry_point: %s" entry_point in
error title content in
trace run_error @@
Ligo.easy_run_typed_simplified ~debug_michelson:true ?amount:options.amount entry_point program input in
Ligo.easy_run_typed_simplified ~debug_michelson:false ?amount:options.amount entry_point program input in
let expect_error =
let title () = "expect result" in
let content () = Format.asprintf "Expected %a, got %a"