Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add with_hash to transaction to_h #178

Merged
merged 2 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
rpc.send_transaction(transaction.to_h(false))
end

def compute_transaction_hash(transaction)
rpc.compute_transaction_hash(transaction.to_h)
rpc.compute_transaction_hash(transaction.to_h(false))
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)
result = rpc.dry_run_transaction(transaction.to_h(false))
Types::DryRunResult.from_h(result)
end

Expand Down
4 changes: 2 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
def to_h(with_hash = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A boolean param is not good here - what if we want to exclude another property? Then we'd have to_h(with_hash = true, with_xxx = true).

I suggest we keep all properties in the model, but strip (exclude) the txhash when calling rpc.

Copy link
Collaborator Author

@shaojunda shaojunda Sep 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it make sense, I will fix this.

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

Expand Down