From 733e69275642c5a20b7873a4cdc1170a5b2d3e4b Mon Sep 17 00:00:00 2001 From: classicalliu Date: Sat, 10 Aug 2019 13:36:53 +0800 Subject: [PATCH] feat: skip data and type in wallet when get unspent cells --- lib/ckb/wallet.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/ckb/wallet.rb b/lib/ckb/wallet.rb index 2bc12b1c..644a81c9 100644 --- a/lib/ckb/wallet.rb +++ b/lib/ckb/wallet.rb @@ -11,9 +11,11 @@ class Wallet attr_reader :addr attr_reader :address + attr_accessor :skip_data_and_type + # @param api [CKB::API] # @param key [CKB::Key | String] Key or pubkey - def initialize(api, key) + def initialize(api, key, skip_data_and_type: true) @api = api if key.is_a?(CKB::Key) @key = key @@ -24,6 +26,7 @@ def initialize(api, key) end @addr = Address.from_pubkey(@pubkey) @address = @addr.to_s + @skip_data_and_type = skip_data_and_type end def self.from_hex(api, privkey) @@ -38,7 +41,14 @@ def get_unspent_cells while current_from <= to current_to = [current_from + 100, to].min cells = api.get_cells_by_lock_hash(lock_hash, current_from.to_s, current_to.to_s) - results.concat(cells) + if skip_data_and_type + cells.each do |cell| + output = api.get_live_cell(cell.out_point).cell + results << cell if (output.data.nil? || output.data == "0x") && output.type.nil? + end + else + results.concat(cells) + end current_from = current_to + 1 end results