Last active
January 24, 2019 20:15
-
-
Save werner/6670dd9bfda7815921658d0c7b4cf0b5 to your computer and use it in GitHub Desktop.
Keoken ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bitcoin' | |
KEOKEN_PREFIX_SIZE = '04' | |
KEOKEN_PREFIX = '00004b50' | |
KEOKEN_VERSION = '0000' | |
KEOKEN_TYPE_CREATE_ASSET = '0000' | |
KEOKEN_TYPE_SEND_TOKEN = '0001' | |
PREFIX_BYTE_AMOUNT = "0000000000000000" | |
AMOUNT_TOKEN_TO_CREATE = 1000000.to_s(16) | |
AMOUNT_SIZE = 16 | |
extend Bitcoin::Builder | |
Bitcoin.network = :testnet3 | |
key = Bitcoin::Key.from_base58("cShKfHoHVf6iKKZym18ip1MJFQFxJwbcLxW53MQikxdDsGd2oxBU") | |
asset = "werner-a-e-token" | |
asset_bytes = asset.bytes.map{|n| n.to_s(16)} | |
asset_name = (asset_bytes + ['00']) | |
data_script = [KEOKEN_VERSION, KEOKEN_TYPE_CREATE_ASSET, asset_name, PREFIX_BYTE_AMOUNT[0..(AMOUNT_SIZE - AMOUNT_TOKEN_TO_CREATE.to_s.length - 1)] + AMOUNT_TOKEN_TO_CREATE.to_s].flatten.join | |
length = data_script.htb.bytesize.to_s(16) | |
script = [Bitcoin::Script::OP_RETURN.to_s(16), KEOKEN_PREFIX_SIZE, KEOKEN_PREFIX, length].join + data_script | |
class Bitcoin::Script | |
def self.to_custom_script(data=nil) | |
[data].pack("H*") | |
end | |
end | |
tx = build_tx {|t| t.input { |i| i.prev_out('330116075cc2c4f15a510f5e549568befc41a775f2e2e1b1fc7ba6620e6b56d1', 1, '76a9147bb97684cc43e2f8ea0ed1d50dddce3ebf80063888ac'.htb, 10000000, 0); i.signature_key(key) } ; t.output {|o| o.value 9991999; o.script {|s| s.recipient key.addr } }; t.output {|o| o.value 0; o.to(script, :custom) } } | |
#https://tbch.blockdozer.com/insight-api/tx/send | |
#https://explorer.testnet.keoken.io/#/pages/assets | |
puts tx.to_payload.bth | |
##################################################################################################################################################################### | |
PREFIX_BYTE_ASSET_ID = "00000000" | |
ASSET_ID_SIZE = 8 | |
id = 23.to_s(16) | |
AMOUNT_TOKEN_TO_SEND = 100.to_s(16) | |
data_script = [KEOKEN_VERSION, KEOKEN_TYPE_SEND_TOKEN, PREFIX_BYTE_ASSET_ID[0..(ASSET_ID_SIZE - id.to_s.length - 1)] + id, PREFIX_BYTE_AMOUNT[0..(AMOUNT_SIZE - AMOUNT_TOKEN_TO_SEND.to_s.length - 1)] + AMOUNT_TOKEN_TO_SEND.to_s].flatten.join | |
length = data_script.htb.bytesize.to_s(16) | |
script = [Bitcoin::Script::OP_RETURN.to_s(16), KEOKEN_PREFIX_SIZE, KEOKEN_PREFIX, length].join + data_script | |
key2 = Bitcoin::Key.from_base58("cSaS8pxky17AwHkf6YxpzRBQCsceFxVFyvY6k8oXD9fd8xfJHvME") | |
tx = build_tx {|t| t.input { |i| i.prev_out('48c158109ca432e109971ca61e4bccbdc2b51053c02f8183f5ca7f60a55df4d0', 0, '76a9147bb97684cc43e2f8ea0ed1d50dddce3ebf80063888ac'.htb, 9991999, 0); i.signature_key(key) } ; t.output {|o| o.value 1000000; o.script {|s| s.recipient key2.addr } }; t.output {|o| o.value 8985999; o.script {|s| s.recipient key.addr } }; t.output {|o| o.value 0; o.to(script, :custom) } } | |
puts length | |
puts tx.to_payload.bth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment