Alpha: remove assets.
This commit is contained in:
parent
2ed66ea569
commit
62ed003957
@ -109,7 +109,6 @@ module Context = struct
|
||||
spendable: bool ;
|
||||
delegate: bool * public_key_hash option ;
|
||||
script: Script.t option ;
|
||||
assets: Asset.Map.t ;
|
||||
counter: int32 ;
|
||||
}
|
||||
let get cctxt b c =
|
||||
@ -128,8 +127,6 @@ module Context = struct
|
||||
call_error_service2 cctxt Services.Context.Contract.delegatable b c ()
|
||||
let script cctxt b c =
|
||||
call_error_service2 cctxt Services.Context.Contract.script b c ()
|
||||
let assets cctxt b c =
|
||||
call_error_service2 cctxt Services.Context.Contract.assets b c ()
|
||||
end
|
||||
|
||||
end
|
||||
@ -212,10 +209,6 @@ module Helpers = struct
|
||||
delegatable ;
|
||||
credit = balance }
|
||||
]
|
||||
let issuance cctxt
|
||||
block ~net ~source ?sourcePubKey ~counter ~assetType ~quantity ~fee ()=
|
||||
operations cctxt block ~net ~source ?sourcePubKey ~counter ~fee
|
||||
Tezos_context.[Issuance { asset = assetType ; amount = quantity }]
|
||||
let delegation cctxt
|
||||
block ~net ~source ?sourcePubKey ~counter ~fee delegate =
|
||||
operations cctxt block ~net ~source ?sourcePubKey ~counter ~fee
|
||||
|
@ -92,7 +92,6 @@ module Context : sig
|
||||
spendable: bool ;
|
||||
delegate: bool * public_key_hash option ;
|
||||
script: Script.t option ;
|
||||
assets: Asset.Map.t ;
|
||||
counter: int32 ;
|
||||
}
|
||||
val get:
|
||||
@ -125,10 +124,6 @@ module Context : sig
|
||||
val script:
|
||||
Client_commands.context ->
|
||||
block -> Contract.t -> Script.t option tzresult Lwt.t
|
||||
val assets:
|
||||
Client_commands.context ->
|
||||
block -> Contract.t ->
|
||||
Asset.Map.t tzresult Lwt.t
|
||||
end
|
||||
end
|
||||
|
||||
@ -227,17 +222,6 @@ module Helpers : sig
|
||||
fee:Tez.t->
|
||||
unit ->
|
||||
MBytes.t tzresult Lwt.t
|
||||
val issuance:
|
||||
Client_commands.context ->
|
||||
block ->
|
||||
net:Updater.Net_id.t ->
|
||||
source:Contract.t ->
|
||||
?sourcePubKey:public_key ->
|
||||
counter:int32 ->
|
||||
assetType:(Asset.t * public_key_hash) ->
|
||||
quantity:Tez.t ->
|
||||
fee:Tez.t ->
|
||||
unit -> MBytes.t tzresult Lwt.t
|
||||
val delegation:
|
||||
Client_commands.context ->
|
||||
block ->
|
||||
|
@ -19,7 +19,6 @@
|
||||
"Script_repr",
|
||||
"Contract_repr",
|
||||
"Roll_repr",
|
||||
"Asset_repr",
|
||||
"Vote_repr",
|
||||
"Operation_repr",
|
||||
"Block_repr",
|
||||
|
@ -93,10 +93,6 @@ let apply_manager_operation_content ctxt origination_nonce accept_failing_script
|
||||
?script
|
||||
~spendable ~delegatable >>=? fun (ctxt, _, origination_nonce) ->
|
||||
return (ctxt, origination_nonce)
|
||||
| Issuance { asset = (asset, key); amount } ->
|
||||
Contract.issue ctxt source asset key amount >>=? fun ctxt ->
|
||||
return (ctxt, origination_nonce)
|
||||
(* TODO: pay for the storage diff *)
|
||||
| Delegation delegate ->
|
||||
Contract.set_delegate ctxt source delegate >>=? fun ctxt ->
|
||||
return (ctxt, origination_nonce)
|
||||
|
@ -1,61 +0,0 @@
|
||||
(**************************************************************************)
|
||||
(* *)
|
||||
(* Copyright (c) 2014 - 2016. *)
|
||||
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
||||
(* *)
|
||||
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
||||
(* *)
|
||||
(**************************************************************************)
|
||||
|
||||
type t = int32
|
||||
type asset = t
|
||||
let of_int32 i = i
|
||||
let to_int32 i = i
|
||||
|
||||
let encoding =
|
||||
let open Data_encoding in
|
||||
describe
|
||||
~title: "Asset type"
|
||||
~description: "A type of asset"
|
||||
(conv to_int32 of_int32 int32)
|
||||
|
||||
|
||||
module Map = struct
|
||||
module Raw = Map.Make(struct
|
||||
type t = asset * Ed25519.Public_key_hash.t
|
||||
let compare (a1, pk1) (a2, pk2) =
|
||||
if Compare.Int32.(a1 = a2) then
|
||||
Ed25519.Public_key_hash.compare pk1 pk2
|
||||
else
|
||||
Compare.Int32.compare a1 a2
|
||||
end)
|
||||
type t = Tez_repr.tez Raw.t
|
||||
let empty = Raw.empty
|
||||
let add map asset key quantity =
|
||||
let previous_quantity =
|
||||
try Raw.find (asset, key) map
|
||||
with Not_found -> Tez_repr.zero in
|
||||
Tez_repr.(previous_quantity +? quantity) >>? fun total ->
|
||||
ok (Raw.add (asset, key) total map)
|
||||
|
||||
let of_tuple_list_exn tl =
|
||||
List.fold_left
|
||||
(fun map (key, qty) -> Raw.add key qty map)
|
||||
Raw.empty tl
|
||||
|
||||
|
||||
let encoding =
|
||||
let open Data_encoding in
|
||||
describe
|
||||
~title: "Assets"
|
||||
~description: "A list of assets held in the contract"
|
||||
(conv
|
||||
Raw.bindings
|
||||
(Json.wrap_error of_tuple_list_exn)
|
||||
(list
|
||||
(tup2
|
||||
(tup2 encoding Ed25519.Public_key_hash.encoding)
|
||||
Tez_repr.encoding)))
|
||||
|
||||
end
|
||||
|
@ -1,22 +0,0 @@
|
||||
(**************************************************************************)
|
||||
(* *)
|
||||
(* Copyright (c) 2014 - 2016. *)
|
||||
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
||||
(* *)
|
||||
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
||||
(* *)
|
||||
(**************************************************************************)
|
||||
|
||||
type t
|
||||
type asset = t
|
||||
|
||||
val encoding: asset Data_encoding.t
|
||||
val of_int32 : int32 -> asset
|
||||
|
||||
module Map : sig
|
||||
type t
|
||||
val empty: t
|
||||
val add:
|
||||
t -> asset -> Ed25519.Public_key_hash.t -> Tez_repr.tez -> t tzresult
|
||||
val encoding: t Data_encoding.t
|
||||
end
|
@ -155,7 +155,6 @@ let create_base c contract ~balance ~manager ~delegate ?script ~spendable ~deleg
|
||||
end >>=? fun c ->
|
||||
Storage.Contract.Spendable.init c contract spendable >>=? fun c ->
|
||||
Storage.Contract.Delegatable.init c contract delegatable >>=? fun c ->
|
||||
Storage.Contract.Assets.init c contract Asset_repr.Map.empty >>=? fun c ->
|
||||
Storage.Contract.Counter.init c contract counter >>=? fun c ->
|
||||
(match script with
|
||||
| Some ({ Script_repr.code ; storage }, (code_fees, storage_fees)) ->
|
||||
@ -266,15 +265,6 @@ let get_balance c contract =
|
||||
end
|
||||
| Some v -> return v
|
||||
|
||||
let get_assets c contract =
|
||||
Storage.Contract.Assets.get_option c contract >>=? function
|
||||
| None -> begin
|
||||
match Contract_repr.is_default contract with
|
||||
| Some _ -> return Asset_repr.Map.empty
|
||||
| None -> failwith "get_assets"
|
||||
end
|
||||
| Some a -> return a
|
||||
|
||||
let is_delegatable c contract =
|
||||
Storage.Contract.Delegatable.get_option c contract >>=? function
|
||||
| None -> begin
|
||||
@ -362,15 +352,6 @@ let credit c contract amount =
|
||||
Storage.Contract.Balance.set c contract balance >>=? fun c ->
|
||||
Roll_storage.Contract.add_amount c contract amount
|
||||
|
||||
let issue c contract asset key quantity =
|
||||
Storage.Contract.Assets.get_option c contract >>=? function
|
||||
| None ->
|
||||
Lwt.return (Asset_repr.Map.add Asset_repr.Map.empty asset key quantity) >>=?
|
||||
Storage.Contract.Assets.set c contract
|
||||
| Some assets ->
|
||||
Lwt.return (Asset_repr.Map.add assets asset key quantity) >>=?
|
||||
Storage.Contract.Assets.set c contract
|
||||
|
||||
let spend c contract amount =
|
||||
Storage.Contract.Spendable.get c contract >>=? fun spendable ->
|
||||
if not spendable
|
||||
|
@ -34,7 +34,6 @@ val is_spendable : Storage.t -> Contract_repr.t -> bool tzresult Lwt.t
|
||||
val get_manager: Storage.t -> Contract_repr.t -> Ed25519.Public_key_hash.t tzresult Lwt.t
|
||||
val get_delegate_opt: Storage.t -> Contract_repr.t -> Ed25519.Public_key_hash.t option tzresult Lwt.t
|
||||
val get_balance: Storage.t -> Contract_repr.t -> Tez_repr.t tzresult Lwt.t
|
||||
val get_assets: Storage.t -> Contract_repr.t -> Asset_repr.Map.t tzresult Lwt.t
|
||||
val get_counter: Storage.t -> Contract_repr.t -> int32 tzresult Lwt.t
|
||||
|
||||
val get_script: Storage.t -> Contract_repr.t -> Script_repr.t option tzresult Lwt.t
|
||||
@ -52,9 +51,6 @@ val spend : Storage.t -> Contract_repr.t -> Tez_repr.t -> Storage.t tzresult Lwt
|
||||
(** decrease_balance even if the contract is not spendable *)
|
||||
val spend_from_script : Storage.t -> Contract_repr.t -> Tez_repr.t -> Storage.t tzresult Lwt.t
|
||||
|
||||
val issue :
|
||||
Storage.t -> Contract_repr.t -> Asset_repr.t -> Ed25519.Public_key_hash.t -> Tez_repr.t -> Storage.t tzresult Lwt.t
|
||||
|
||||
val originate :
|
||||
Storage.t ->
|
||||
Contract_repr.origination_nonce ->
|
||||
|
@ -58,10 +58,6 @@ and manager_operation =
|
||||
delegatable: bool ;
|
||||
credit: Tez_repr.tez ;
|
||||
}
|
||||
| Issuance of {
|
||||
asset: Asset_repr.asset * Ed25519.Public_key_hash.t ;
|
||||
amount: Tez_repr.tez ;
|
||||
}
|
||||
| Delegation of Ed25519.Public_key_hash.t option
|
||||
|
||||
and delegate_operation =
|
||||
@ -131,19 +127,6 @@ module Encoding = struct
|
||||
Origination
|
||||
{manager ; credit ; spendable ; delegatable ; delegate ; script })
|
||||
|
||||
let issuance_encoding =
|
||||
(obj3
|
||||
(req "kind" (constant "issuance"))
|
||||
(req "asset" (tup2 Asset_repr.encoding Ed25519.Public_key_hash.encoding))
|
||||
(req "quantity" Tez_repr.encoding))
|
||||
|
||||
let issuance_case tag =
|
||||
case ~tag issuance_encoding
|
||||
(function
|
||||
| Issuance { asset ; amount } -> Some ((), asset, amount)
|
||||
| _ -> None)
|
||||
(fun ((), asset, amount) -> Issuance { asset ; amount })
|
||||
|
||||
let delegation_encoding =
|
||||
(obj2
|
||||
(req "kind" (constant "delegation"))
|
||||
@ -164,8 +147,7 @@ module Encoding = struct
|
||||
(list (union ~tag_size:`Uint8 [
|
||||
transaction_case 0 ;
|
||||
origination_case 1 ;
|
||||
issuance_case 2 ;
|
||||
delegation_case 3 ;
|
||||
delegation_case 2 ;
|
||||
]))))
|
||||
|
||||
let manager_kind_case tag =
|
||||
|
@ -58,10 +58,6 @@ and manager_operation =
|
||||
delegatable: bool ;
|
||||
credit: Tez_repr.tez ;
|
||||
}
|
||||
| Issuance of {
|
||||
asset: Asset_repr.t * Ed25519.Public_key_hash.t ;
|
||||
amount: Tez_repr.tez ;
|
||||
}
|
||||
| Delegation of Ed25519.Public_key_hash.t option
|
||||
|
||||
and delegate_operation =
|
||||
|
@ -256,20 +256,12 @@ module Context = struct
|
||||
~output: (wrap_tzerror (option Script.encoding))
|
||||
RPC.Path.(custom_root / "context" / "contracts" /: Contract.arg / "script")
|
||||
|
||||
let assets custom_root =
|
||||
RPC.service
|
||||
~description: "Access the assets of the contract."
|
||||
~input: empty
|
||||
~output: (wrap_tzerror Asset.Map.encoding)
|
||||
RPC.Path.(custom_root / "context" / "contracts" /: Contract.arg / "assets")
|
||||
|
||||
type info = {
|
||||
manager: public_key_hash ;
|
||||
balance: Tez.t ;
|
||||
spendable: bool ;
|
||||
delegate: bool * public_key_hash option ;
|
||||
script: Script.t option ;
|
||||
assets: Asset.Map.t ;
|
||||
counter: int32 ;
|
||||
}
|
||||
|
||||
@ -280,11 +272,11 @@ module Context = struct
|
||||
~output:
|
||||
(wrap_tzerror @@
|
||||
conv
|
||||
(fun {manager;balance;spendable;delegate;script;assets;counter} ->
|
||||
(manager,balance,spendable,delegate,script,assets,counter))
|
||||
(fun (manager,balance,spendable,delegate,script,assets,counter) ->
|
||||
{manager;balance;spendable;delegate;script;assets;counter}) @@
|
||||
obj7
|
||||
(fun {manager;balance;spendable;delegate;script;counter} ->
|
||||
(manager,balance,spendable,delegate,script,counter))
|
||||
(fun (manager,balance,spendable,delegate,script,counter) ->
|
||||
{manager;balance;spendable;delegate;script;counter}) @@
|
||||
obj6
|
||||
(req "manager" Ed25519.Public_key_hash.encoding)
|
||||
(req "balance" Tez.encoding)
|
||||
(req "spendable" bool)
|
||||
@ -292,7 +284,6 @@ module Context = struct
|
||||
(req "setable" bool)
|
||||
(opt "value" Ed25519.Public_key_hash.encoding))
|
||||
(opt "script" Script.encoding)
|
||||
(req "assets" Asset.Map.encoding)
|
||||
(req "counter" int32))
|
||||
RPC.Path.(custom_root / "context" / "contracts" /: Contract.arg)
|
||||
|
||||
|
@ -153,7 +153,6 @@ let () =
|
||||
register2' Services.Context.Contract.spendable Contract.is_spendable ;
|
||||
register2' Services.Context.Contract.delegatable Contract.is_delegatable ;
|
||||
register2' Services.Context.Contract.script Contract.get_script ;
|
||||
register2' Services.Context.Contract.assets Contract.get_assets ;
|
||||
register2' Services.Context.Contract.get (fun ctxt contract ->
|
||||
Contract.get_balance ctxt contract >>=? fun balance ->
|
||||
Contract.get_manager ctxt contract >>=? fun manager ->
|
||||
@ -162,10 +161,9 @@ let () =
|
||||
Contract.is_delegatable ctxt contract >>=? fun delegatable ->
|
||||
Contract.is_spendable ctxt contract >>=? fun spendable ->
|
||||
Contract.get_script ctxt contract >>=? fun script ->
|
||||
Contract.get_assets ctxt contract >>=? fun assets ->
|
||||
return { Services.Context.Contract.manager ; balance ;
|
||||
spendable ; delegate = (delegatable, delegate) ;
|
||||
script ; assets ; counter }) ;
|
||||
script ; counter }) ;
|
||||
()
|
||||
|
||||
(*-- Helpers -----------------------------------------------------------------*)
|
||||
|
@ -108,7 +108,6 @@ module Key = struct
|
||||
let roll_list c = contract_store c ["roll_list"]
|
||||
let change c = contract_store c ["change"]
|
||||
let balance c = contract_store c ["balance"]
|
||||
let assets c = contract_store c ["assets"]
|
||||
let manager c = contract_store c ["manager"]
|
||||
let spendable c = contract_store c ["spendable"]
|
||||
let delegatable c = contract_store c ["delegatable"]
|
||||
@ -250,16 +249,6 @@ module Contract = struct
|
||||
let encoding = Tez_repr.encoding
|
||||
end)
|
||||
|
||||
module Assets =
|
||||
Make_indexed_data_storage(
|
||||
struct
|
||||
type key = Contract_repr.t
|
||||
type value = Asset_repr.Map.t
|
||||
let name = "contract assets"
|
||||
let key = Key.Contract.assets
|
||||
let encoding = Asset_repr.Map.encoding
|
||||
end)
|
||||
|
||||
module Manager =
|
||||
Make_indexed_data_storage(struct
|
||||
type key = Contract_repr.t
|
||||
|
@ -132,11 +132,6 @@ module Contract : sig
|
||||
and type value = Tez_repr.t
|
||||
and type context := t
|
||||
|
||||
module Assets : Indexed_data_storage
|
||||
with type key = Contract_repr.t
|
||||
and type value = Asset_repr.Map.t
|
||||
and type context := t
|
||||
|
||||
(** The manager of a contract *)
|
||||
module Manager : Indexed_data_storage
|
||||
with type key = Contract_repr.t
|
||||
|
@ -108,8 +108,6 @@ module Fitness = struct
|
||||
|
||||
end
|
||||
|
||||
module Asset = Asset_repr
|
||||
|
||||
let init = Init_storage.may_initialize
|
||||
|
||||
let finalize ?commit_message c =
|
||||
|
@ -148,16 +148,6 @@ module Script : sig
|
||||
|
||||
end
|
||||
|
||||
module Asset : sig
|
||||
type t
|
||||
type asset = t
|
||||
val encoding: asset Data_encoding.t
|
||||
module Map : sig
|
||||
type t
|
||||
val encoding: t Data_encoding.t
|
||||
end
|
||||
end
|
||||
|
||||
module Bootstrap : sig
|
||||
type account = {
|
||||
public_key_hash: public_key_hash ;
|
||||
@ -346,8 +336,6 @@ module Contract : sig
|
||||
val get_counter: context -> contract -> int32 tzresult Lwt.t
|
||||
val get_balance:
|
||||
context -> contract -> Tez.t tzresult Lwt.t
|
||||
val get_assets:
|
||||
context -> contract -> Asset.Map.t tzresult Lwt.t
|
||||
|
||||
val set_delegate:
|
||||
context -> contract -> public_key_hash option -> context tzresult Lwt.t
|
||||
@ -373,9 +361,6 @@ module Contract : sig
|
||||
|
||||
val credit:
|
||||
context -> contract -> Tez.t -> context tzresult Lwt.t
|
||||
val issue:
|
||||
context -> contract ->
|
||||
Asset.t -> public_key_hash -> Tez.t -> context tzresult Lwt.t
|
||||
|
||||
val update_script_storage_and_fees:
|
||||
context -> contract -> Tez.t -> Script.expr -> context tzresult Lwt.t
|
||||
@ -483,10 +468,6 @@ and manager_operation =
|
||||
delegatable: bool ;
|
||||
credit: Tez.t ;
|
||||
}
|
||||
| Issuance of {
|
||||
asset: Asset.t * public_key_hash ;
|
||||
amount: Tez.t ;
|
||||
}
|
||||
| Delegation of public_key_hash option
|
||||
|
||||
and delegate_operation =
|
||||
|
Loading…
Reference in New Issue
Block a user