Skip to content

Commit

Permalink
feat: add to_raw_transaction_h method
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Sep 18, 2019
1 parent 55abb63 commit 9e14366
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/ckb/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ def get_live_cell(out_point, with_data = false)
#
# @return [String] tx_hash
def send_transaction(transaction)
rpc.send_transaction(transaction.to_h(false))
rpc.send_transaction(transaction.to_raw_transaction_h)
end

def compute_transaction_hash(transaction)
rpc.compute_transaction_hash(transaction.to_h(false))
rpc.compute_transaction_hash(transaction.to_raw_transaction_h)
end

def compute_script_hash(script)
Expand Down Expand Up @@ -195,7 +195,7 @@ def get_peers_state
#
# @return [CKB::Types::DryRunResult]
def dry_run_transaction(transaction)
result = rpc.dry_run_transaction(transaction.to_h(false))
result = rpc.dry_run_transaction(transaction.to_raw_transaction_h)
Types::DryRunResult.from_h(result)
end

Expand Down
16 changes: 14 additions & 2 deletions lib/ckb/types/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def sign(key, tx_hash)
)
end

def to_h(with_hash = true)
def to_h
hash = {
version: Utils.to_hex(@version),
cell_deps: @cell_deps.map(&:to_h),
Expand All @@ -72,10 +72,22 @@ def to_h(with_hash = true)
outputs_data: @outputs_data,
witnesses: @witnesses.map(&:to_h)
}
hash[:hash] = @hash if @hash && with_hash
hash[:hash] = @hash if @hash
hash
end

def to_raw_transaction_h
{
version: Utils.to_hex(@version),
cell_deps: @cell_deps.map(&:to_h),
header_deps: @header_deps,
inputs: @inputs.map(&:to_h),
outputs: @outputs.map(&:to_h),
outputs_data: @outputs_data,
witnesses: @witnesses.map(&:to_h)
}
end

def compute_hash
raw_transaction_serializer = CKB::Serializers::RawTransactionSerializer.new(self)
blake2b = CKB::Blake2b.new
Expand Down

0 comments on commit 9e14366

Please sign in to comment.