Commit 34d5980a authored by Jakob Botsch Nielsen's avatar Jakob Botsch Nielsen
Browse files

Minor cleanups and add .editorconfig

parent c9329d33
Pipeline #11089 passed with stage
in 4 minutes and 46 seconds
# editorconfig.org
# top-most EditorConfig file
root = true
[*]
insert_final_newline = true
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
From Coq Require Import String. From Coq Require Import String.
From Coq Require OrderedTypeEx. From Coq Require OrderedTypeEx.
From SmartContracts Require Import Oak. From SmartContracts Require Import Oak.
From SmartContracts Require Import Monads. From SmartContracts Require Import Monads.
...@@ -30,7 +31,7 @@ Inductive TxBody := ...@@ -30,7 +31,7 @@ Inductive TxBody :=
| tx_empty | tx_empty
| tx_deploy (deployment : ContractDeployment) | tx_deploy (deployment : ContractDeployment)
| tx_call (message : OakValue). | tx_call (message : OakValue).
Record Tx := Record Tx :=
build_tx { build_tx {
tx_from : Address; tx_from : Address;
...@@ -72,45 +73,47 @@ Instance impl_interface : interface := ...@@ -72,45 +73,47 @@ Instance impl_interface : interface :=
todo: come back to this and understand universe polymorphism in depth. *) todo: come back to this and understand universe polymorphism in depth. *)
Polymorphic Record ChainInterface := Polymorphic Record ChainInterface :=
build_chain_interface { build_chain_interface {
ifc_chain_type : Type; (* Would be nice to encapsulate ChainInterface somewhat here
ifc_chain_at : ifc_chain_type -> BlockId -> option ifc_chain_type; and avoid these ugly prefixed names *)
ifc_head_block : ifc_chain_type -> Block; ci_chain_type : Type;
ifc_incoming_txs : ifc_chain_type -> Address -> list Tx; ci_chain_at : ci_chain_type -> BlockId -> option ci_chain_type;
ifc_outgoing_txs : ifc_chain_type -> Address -> list Tx; ci_head_block : ci_chain_type -> Block;
ifc_contract_deployment : ifc_chain_type -> Address -> option ContractDeployment; ci_incoming_txs : ci_chain_type -> Address -> list Tx;
ifc_contract_state : ifc_chain_type -> Address -> option OakValue; ci_outgoing_txs : ci_chain_type -> Address -> list Tx;
ci_contract_deployment : ci_chain_type -> Address -> option ContractDeployment;
ci_contract_state : ci_chain_type -> Address -> option OakValue;
}. }.
Record Chain := Record Chain :=
build_chain { build_chain {
chain_ifc : ChainInterface; chain_ci : ChainInterface;
chain_val : ifc_chain_type chain_ifc chain_val : chain_ci.(ci_chain_type);
}. }.
Definition chain_at (c : Chain) (bid : BlockId) : option Chain := Definition chain_at (c : Chain) (bid : BlockId) : option Chain :=
do x <- c.(chain_ifc).(ifc_chain_at) c.(chain_val) bid; do x <- c.(chain_ci).(ci_chain_at) c.(chain_val) bid;
Some {| chain_val := x |}. Some {| chain_val := x |}.
Definition head_block (c : Chain) := Definition head_block (c : Chain) :=
c.(chain_ifc).(ifc_head_block) c.(chain_val). c.(chain_ci).(ci_head_block) c.(chain_val).
Definition block_at (c : Chain) (bid : BlockId) : option Block := Definition block_at (c : Chain) (bid : BlockId) : option Block :=
do c <- chain_at c bid; Some (head_block c). do c <- chain_at c bid; Some (head_block c).
Definition incoming_txs (c : Chain) := Definition incoming_txs (c : Chain) :=
c.(chain_ifc).(ifc_incoming_txs) c.(chain_val). c.(chain_ci).(ci_incoming_txs) c.(chain_val).
Definition outgoing_txs (c : Chain) := Definition outgoing_txs (c : Chain) :=
c.(chain_ifc).(ifc_outgoing_txs) c.(chain_val). c.(chain_ci).(ci_outgoing_txs) c.(chain_val).
Definition contract_deployment (c : Chain) := Definition contract_deployment (c : Chain) :=
c.(chain_ifc).(ifc_contract_deployment) c.(chain_val). c.(chain_ci).(ci_contract_deployment) c.(chain_val).
Definition contract_state (c : Chain) := Definition contract_state (c : Chain) :=
c.(chain_ifc).(ifc_contract_state) c.(chain_val). c.(chain_ci).(ci_contract_state) c.(chain_val).
Inductive ContractCallContext := Inductive ContractCallContext :=
build_contract_call_ctx { build_contract_call_ctx {
(* Chain *) (* Chain *)
ctx_chain : Chain; ctx_chain : Chain;
(* Address sending the funds *) (* Address sending the funds *)
...@@ -119,17 +122,17 @@ build_contract_call_ctx { ...@@ -119,17 +122,17 @@ build_contract_call_ctx {
ctx_contract_address : Address; ctx_contract_address : Address;
(* Amount of GTU passed in call *) (* Amount of GTU passed in call *)
ctx_amount : Amount; ctx_amount : Amount;
}. }.
Inductive ChainAction := Inductive ChainAction :=
| act_transfer (to : Address) (amount : Amount) | act_transfer (to : Address) (amount : Amount)
| act_call (to : Address) (amount : Amount) (msg : OakValue) | act_call (to : Address) (amount : Amount) (msg : OakValue)
| act_deploy | act_deploy
{setup_ty msg_ty state_ty : Type} {setup_ty msg_ty state_ty : Type}
(version : Version) (version : Version)
(init : ContractCallContext -> setup_ty -> option state_ty) (init : ContractCallContext -> setup_ty -> option state_ty)
(receive : ContractCallContext -> state_ty -> (receive : ContractCallContext -> state_ty ->
option msg_ty -> option (state_ty * list ChainAction)). option msg_ty -> option (state_ty * list ChainAction)).
(* (*
Record ContractInterface (setup_ty msg_ty state_ty : Type) := Record ContractInterface (setup_ty msg_ty state_ty : Type) :=
...@@ -178,4 +181,4 @@ Definition get_contract_interface ...@@ -178,4 +181,4 @@ Definition get_contract_interface
call amt msg := act_call addr amt (build_oak_value msg_oty msg) |} call amt msg := act_call addr amt (build_oak_value msg_oty msg) |}
| _, _, _ => None | _, _, _ => None
end. end.
*) *)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment