fa2_convertors.mligo 6.06 KB
Newer Older
1 2 3 4
#if !FA2_CONVERTORS
#define FA2_CONVERTORS

#include "../fa2_interface.mligo"
Eugene Mishura's avatar
Eugene Mishura committed
5 6 7 8 9 10 11 12 13 14 15 16 17

let permissions_descriptor_to_michelson (d : permissions_descriptor)
    : permissions_descriptor_michelson =
  let aux : permissions_descriptor_aux = {
    operator = Layout.convert_to_right_comb d.operator;
    receiver = Layout.convert_to_right_comb d.receiver;
    sender = Layout.convert_to_right_comb d.sender;
    custom = match d.custom with
    | None -> (None : custom_permission_policy_michelson option)
    | Some c -> Some (Layout.convert_to_right_comb c)
  } in
  Layout.convert_to_right_comb aux

18 19 20 21 22 23 24 25 26 27 28
let transfer_descriptor_to_michelson (p : transfer_descriptor) : transfer_descriptor_michelson =
  let aux : transfer_descriptor_aux = {
    from_ = p.from_;
    txs = List.map 
      (fun (tx : transfer_destination_descriptor) ->
        Layout.convert_to_right_comb tx
      )
      p.txs;
  } in
  Layout.convert_to_right_comb aux

Eugene Mishura's avatar
Eugene Mishura committed
29 30 31 32 33
let transfer_descriptor_param_to_michelson (p : transfer_descriptor_param)
    : transfer_descriptor_param_michelson =
  let aux : transfer_descriptor_param_aux = {
    fa2 = p.fa2;
    operator = p.operator;
34
    batch = List.map  transfer_descriptor_to_michelson p.batch;
Eugene Mishura's avatar
Eugene Mishura committed
35 36 37
  } in
  Layout.convert_to_right_comb aux

38 39 40 41 42 43 44 45 46 47 48 49 50
let transfer_descriptor_from_michelson (p : transfer_descriptor_michelson) : transfer_descriptor =
  let aux : transfer_descriptor_aux = Layout.convert_from_right_comb p in
  {
    from_ = aux.from_;
    txs = List.map
      (fun (txm : transfer_destination_descriptor_michelson) ->
        let tx : transfer_destination_descriptor =
          Layout.convert_from_right_comb txm in
        tx
      )
      aux.txs;
  }

Eugene Mishura's avatar
Eugene Mishura committed
51 52 53
let transfer_descriptor_param_from_michelson (p : transfer_descriptor_param_michelson)
    : transfer_descriptor_param =
  let aux : transfer_descriptor_param_aux = Layout.convert_from_right_comb p in
54 55
  let b : transfer_descriptor list =
    List.map transfer_descriptor_from_michelson aux.batch
Eugene Mishura's avatar
Eugene Mishura committed
56 57 58 59 60
  in
  {
    fa2 = aux.fa2;
    operator = aux.operator;
    batch = b;
Eugene Mishura's avatar
Eugene Mishura committed
61 62
  }

63 64 65 66 67 68 69 70 71 72 73 74
let transfer_from_michelson (txm : transfer_michelson) : transfer =
  let aux : transfer_aux = Layout.convert_from_right_comb txm in 
  {
    from_ = aux.from_;
    txs = List.map
      (fun (txm : transfer_destination_michelson) ->
        let tx : transfer_destination = Layout.convert_from_right_comb txm in
        tx
      )
      aux.txs;
  }

Eugene Mishura's avatar
Eugene Mishura committed
75
let transfers_from_michelson (txsm : transfer_michelson list) : transfer list =
76
  List.map transfer_from_michelson txsm
Eugene Mishura's avatar
Eugene Mishura committed
77 78

let operator_param_from_michelson (p : operator_param_michelson) : operator_param =
79 80
  let op : operator_param = Layout.convert_from_right_comb p in
  op
Eugene Mishura's avatar
Eugene Mishura committed
81 82

let operator_param_to_michelson (p : operator_param) : operator_param_michelson =
83
  Layout.convert_to_right_comb p
Eugene Mishura's avatar
Eugene Mishura committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175

let operator_update_from_michelson (uom : update_operator_michelson) : update_operator =
    let aux : update_operator_aux = Layout.convert_from_right_comb uom in
    match aux with
    | Add_operator opm -> Add_operator_p (operator_param_from_michelson opm)
    | Remove_operator opm -> Remove_operator_p (operator_param_from_michelson opm)

let operator_update_to_michelson (uo : update_operator) : update_operator_michelson =
    let aux = match uo with
    | Add_operator_p op -> Add_operator (operator_param_to_michelson op)
    | Remove_operator_p op -> Remove_operator (operator_param_to_michelson op)
    in
    Layout.convert_to_right_comb aux

let operator_updates_from_michelson (updates_michelson : update_operator_michelson list)
    : update_operator list =
  List.map operator_update_from_michelson updates_michelson

let is_operator_param_from_michelson (p : is_operator_param_michelson) : is_operator_param =
  let aux : is_operator_param_aux = Layout.convert_from_right_comb p in
  {
    operator = operator_param_from_michelson aux.operator;
    callback = aux.callback;
  }

let is_operator_param_to_michelson (p : is_operator_param) : is_operator_param_michelson =
  let aux : is_operator_param_aux = 
  {
    operator = operator_param_to_michelson p.operator;
    callback = p.callback;
  } in
  Layout.convert_to_right_comb aux

let is_operator_response_to_michelson (r : is_operator_response) : is_operator_response_michelson =
  let aux : is_operator_response_aux = {
    operator = operator_param_to_michelson r.operator;
    is_operator = r.is_operator;
  } in
  Layout.convert_to_right_comb aux

let balance_of_param_from_michelson (p : balance_of_param_michelson) : balance_of_param =
  let aux : balance_of_param_aux = Layout.convert_from_right_comb p in
  let requests = List.map 
    (fun (rm : balance_of_request_michelson) ->
      let r : balance_of_request = Layout.convert_from_right_comb rm in
      r
    )
    aux.requests 
  in
  {
    requests = requests;
    callback = aux.callback;
  } 

let balance_of_param_to_michelson (p : balance_of_param) : balance_of_param_michelson =
  let aux : balance_of_param_aux = {
    requests = List.map 
      (fun (r : balance_of_request) -> Layout.convert_to_right_comb r)
      p.requests;
    callback = p.callback;
  } in
  Layout.convert_to_right_comb aux

let balance_of_response_to_michelson (r : balance_of_response) : balance_of_response_michelson =
  let aux : balance_of_response_aux = {
    request = Layout.convert_to_right_comb r.request;
    balance = r.balance;
  } in
  Layout.convert_to_right_comb aux

let balance_of_response_from_michelson (rm : balance_of_response_michelson) : balance_of_response =
  let aux : balance_of_response_aux = Layout.convert_from_right_comb rm in
  let request : balance_of_request = Layout.convert_from_right_comb aux.request in
  {
    request = request;
    balance = aux.balance;
  }

let total_supply_responses_to_michelson (rs : total_supply_response list)
    : total_supply_response_michelson list =
  List.map
    (fun (r : total_supply_response) ->
      let rm : total_supply_response_michelson = Layout.convert_to_right_comb r in
      rm
    ) rs

let token_metas_to_michelson (ms : token_metadata list) : token_metadata_michelson list =
  List.map
    ( fun (m : token_metadata) ->
      let mm : token_metadata_michelson = Layout.convert_to_right_comb m in
      mm
    ) ms
176 177

#endif