ckb-demo-ruby
ckb-demo-ruby copied to clipboard
Script modulize
In the scripts/bitcoin folder, there are 8 different sighash combination, but there are many duplicated codes in the script.
All the sighash without the anyonecanpay modifier, the sha3 of inputs are the same:
tx["inputs"].each_with_index do |input, i|
sha3.update(input["hash"])
sha3.update(input["index"].to_s)
sha3.update(CKB.load_script_hash(i, CKB::Source::INPUT, CKB::Category::LOCK))
end
All the sighash with the anyonecanpay modifier:
out_point = CKB.load_input_out_point(0, CKB::Source::CURRENT)
sha3.update(out_point["hash"])
sha3.update(out_point["index"].to_s)
sha3.update(CKB::CellField.new(CKB::Source::CURRENT, 0, CKB::CellField::LOCK_HASH).readall)
Any good way to optimize it? If we want to develop some complicated scripts, like the contract for the layer2 protocol or implement EVM by ruby, it's better to modulize it. It's a universal problem.