lib/ckb/wallet.rb
# Issue a new user defined token using current wallet as token superuser
Issue a new user defined token using current wallet as token superuser
Issue a new user defined token using current wallet as token superuser
def create_udt_token(capacity, token_name, tokens, account_wallet: false)
      token_info = created_token_info(token_name, account_wallet: account_wallet)
      wallet = account_wallet ? udt_account_wallet(token_info) : udt_wallet(token_info)
      i = gather_inputs(capacity, MIN_UDT_CELL_CAPACITY)
      input_capacities = i.capacities
      data = [tokens].pack("Q<")
      s = SHA3::Digest::SHA256.new
      s.update(Ckb::Utils.hex_to_bin(wallet.contract_type_hash))
      s.update(data)
      key = Secp256k1::PrivateKey.new(privkey: privkey)
      signature = key.ecdsa_serialize(key.ecdsa_sign(s.digest, raw: true))
      signature_hex = Ckb::Utils.bin_to_hex(signature)
      outputs = [
        {
          capacity: capacity,
          data: data,
          lock: wallet.address,
          type: {
            version: 0,
            args: [
              signature_hex
            ],
            reference: api.mruby_cell_hash,
            signed_args: [
              Ckb::CONTRACT_SCRIPT,
              token_info.name,
              token_info.pubkey
            ]
          }
        }
      ]
      if input_capacities > capacity
        outputs << {
          capacity: input_capacities - capacity,
          data: "",
          lock: self.address
        }
      end
      tx = {
        version: 0,
        deps: [api.mruby_out_point],
        inputs: Ckb::Utils.sign_sighash_all_inputs(i.inputs, outputs, privkey),
        outputs: outputs
      }
      hash = api.send_transaction(tx)
      OpenStruct.new(tx_hash: hash, token_info: token_info)
    end
def create_udt_token ( capacity , token_name , tokens , account_wallet : false ) token_info = created_token_info ( token_name , account_wallet : account_wallet ) wallet = account_wallet ? udt_account_wallet ( token_info ) : udt_wallet ( token_info ) i = gather_inputs ( capacity , MIN_UDT_CELL_CAPACITY ) input_capacities = i . capacities data = [ tokens ] . pack ( "Q<" ) s = SHA3 :: Digest :: SHA256 . new s . update ( Ckb :: Utils . hex_to_bin ( wallet . contract_type_hash ) ) s . update ( data ) key = Secp256k1 :: PrivateKey . new ( privkey : privkey ) signature = key . ecdsa_serialize ( key . ecdsa_sign ( s . digest , raw : true ) ) signature_hex = Ckb :: Utils . bin_to_hex ( signature ) outputs = [ { capacity : capacity , data : data , lock : wallet . address , type : { version : 0 , args : [ signature_hex ] , reference : api . mruby_cell_hash , signed_args : [ Ckb :: CONTRACT_SCRIPT , token_info . name , token_info . pubkey ] } } ] if input_capacities > capacity outputs << { capacity : input_capacities - capacity , data : "" , lock : self . address } end tx = { version : 0 , deps : [ api . mruby_out_point ] , inputs : Ckb :: Utils . sign_sighash_all_inputs ( i . inputs , outputs , privkey ) , outputs : outputs } hash = api . send_transaction ( tx ) OpenStruct . new ( tx_hash : hash , token_info : token_info ) end
Issue a new user defined token using current wallet as token superuser
Issue a new user defined token using current wallet as token superuser
capacity
token_name
tokens
account_wallet