Skip to content

Commit

Permalink
refactor: rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Apr 25, 2019
1 parent 6f346c5 commit a59158b
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/ckb/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def initialize(host: DEFAULT_URL, mode: MODE::TESTNET)
if mode == MODE::TESTNET
# For testnet chain, we can assume the first cell of the first transaction
# in the genesis block contains default lock script we can use here.
system_cell_transaction = genesis_block[:commit_transactions][0]
system_cell_transaction = genesis_block[:transactions][0]
out_point = {
hash: system_cell_transaction[:hash],
tx_hash: system_cell_transaction[:hash],
index: 0
}
cell_data = CKB::Utils.hex_to_bin(system_cell_transaction[:outputs][0][:data])
Expand Down
2 changes: 1 addition & 1 deletion lib/ckb/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def signature_hex(key)
blake2b = CKB::Blake2b.new
inputs.each do |input|
previous_output = input[:previous_output]
blake2b.update(Utils.hex_to_bin(previous_output[:hash]))
blake2b.update(Utils.hex_to_bin(previous_output[:tx_hash]))
blake2b.update(previous_output[:index].to_s)
end
outputs.each do |output|
Expand Down
4 changes: 2 additions & 2 deletions lib/ckb/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def self.hex_to_bin(hex)

def self.json_script_to_type_hash(script)
blake2b = CKB::Blake2b.new
blake2b << hex_to_bin(script[:binary_hash]) if script[:binary_hash]
blake2b << hex_to_bin(script[:code_hash]) if script[:code_hash]
args = script[:args] || []
args.each do |arg|
blake2b << hex_to_bin(arg)
Expand All @@ -31,7 +31,7 @@ def self.json_script_to_type_hash(script)
def self.generate_lock(target_pubkey_blake160, system_script_cell_hash)
target_pubkey_blake160_bin = CKB::Utils.hex_to_bin(target_pubkey_blake160)
{
binary_hash: system_script_cell_hash,
code_hash: system_script_cell_hash,
args: [
# There are 2 conversions from binary to hex string here:
# 1. The inner unpack1 is required since the deployed lock script
Expand Down
4 changes: 2 additions & 2 deletions lib/ckb/wallet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get_transaction(hash)
def block_assembler_config
%(
[block_assembler]
binary_hash = "#{lock[:binary_hash]}"
code_hash = "#{lock[:code_hash]}"
args = #{lock[:args]}
).strip
end
Expand All @@ -113,7 +113,7 @@ def gather_inputs(capacity, min_capacity)
input = {
previous_output: cell[:out_point],
args: [],
valid_since: "0"
since: "0"
}
pubkeys << pubkey
inputs << input
Expand Down
2 changes: 1 addition & 1 deletion spec/ckb/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
end

it "get transaction" do
tx = api.genesis_block[:"commit_transactions"].first
tx = api.genesis_block[:transactions].first
result = api.get_transaction(tx[:hash])
expect(result).not_to be nil
expect(result[:hash]).to eq tx[:hash]
Expand Down
2 changes: 1 addition & 1 deletion spec/ckb/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def always_success_json_object
)
always_success_cell_hash = Utils.bin_to_hex(hash_bin)
{
binary_hash: always_success_cell_hash,
code_hash: always_success_cell_hash,
args: []
}
end
Expand Down

0 comments on commit a59158b

Please sign in to comment.