Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to lock the contract in bytom

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to lock the contract in bytom". In the daily operation, I believe that many people have doubts about how to lock the contract in bytom. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to lock the contract in bytom". Next, please follow the editor to study!

The template is as follows:

Contract TradeOffer (assetRequested: Asset, amountRequested: Amount, seller: Program, cancelKey: PublicKey) locks offered {clause trade () requires payment: amountRequested of assetRequested {lock payment with seller unlock offered} clause cancel (sellerSig: Signature) {verify checkTxSig (cancelKey, sellerSig) unlock offered}} Lock contract step 1: call create-account-receiver to generate control_program

The following is a related code snippet:

SendHttpPost ("{\" account_id\ ":\" 0IJVD7MNG0A02\ "}", "create-account-receiver", "http://127.0.0.1:9888","");" the second step calls list-pubkeys to get pubkey

The following is a related code snippet:

SendHttpPost ("{\" account_id\ ":\" 0IJVD7MNG0A02\ "}", "list-pubkeys", "http://127.0.0.1:9888","");" step 3: call the values obtained in step 12 to the compile interface to compile the contract to obtain the program contract program

The following is a related code snippet:

JSONObject param=new JSONObject (); JSONArray agrs=new JSONArray (); / / four parameter values of the contract: JSONObject assetParam=new JSONObject (); assetParam.put ("string", "81d097312645696daea84b761d2898d950d8fba0de06c9267d8513b16663dd3a"); agrs.put (assetParam); JSONObject amountParam=new JSONObject (); amountParam.put ("integer", 2000000l); agrs.put (amountParam); JSONObject programParam=new JSONObject () ProgramParam.put ("string", control_program); agrs.put (programParam); JSONObject publicKeyParam=new JSONObject (); publicKeyParam.put ("string", pubkey); agrs.put (publicKeyParam); param.put ("agrs", agrs) Param.put ("contract", "contract TradeOffer (assetRequested: Asset, amountRequested: Amount, seller: Program, cancelKey: PublicKey) locks offered {clause trade () requires payment: amountRequested of assetRequested {lock payment with seller unlock offered} clause cancel (sellerSig: Signature) {verify checkTxSig (cancelKey, sellerSig) unlock offered}}") / / call compilation contract sendHttpPost (param.toString (), "list-pubkeys", "http://127.0.0.1:9888","");" step 4: pass program into build-transaction interface to build a transaction to data

The following is a related code snippet:

Param=new JSONObject (); agrs=new JSONArray (); JSONObject spendAccount=new JSONObject (); spendAccount.put ("account_id", "0H757LPD00A02"); spendAccount.put ("amount", 9909099090000l); spendAccount.put ("asset_id", "161b9767b664df907fa926a31f9e835236e57f3e9ccc5f80c12bd97723322652"); spendAccount.put ("type", "spend_account"); agrs.put (spendAccount) JSONObject controlAccount=new JSONObject (); controlAccount.put ("control_program", program); controlAccount.put ("amount", 9909099090000l); controlAccount.put ("asset_id", "161b9767b664df907fa926a31f9e835236e57f3e9ccc5f80c12bd97723322652"); controlAccount.put ("type", "control_program"); agrs.put (controlAccount); JSONObject spendAccount2=new JSONObject () SpendAccount2.put ("account_id", "0H757LPD00A02"); spendAccount2.put ("amount", 600000l); spendAccount2.put ("asset_id", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); spendAccount2.put ("type", "spend_account"); agrs.put (spendAccount2); param.put ("actions", agrs); param.put ("ttl", 0) SendHttpPost (param.toString (), "build-transaction", "http://127.0.0.1:9888","");" step 5: enter the password to call sign-transaction signature step 4: build's data to get raw_transaction

The following is a related code snippet:

Param=new JSONObject (); param.put ("password", "xxx"); param.put ("transaction", data); sendHttpPost (param.toString (), "sign-transaction", "http://127.0.0.1:9888","");" step 6: call submit-transactions to submit the transaction

The following is a related code snippet:

Param=new JSONObject (); param.put ("raw_transaction", raw_transaction); sendHttpPost (param.toString (), "submit-transactions", "http://127.0.0.1:9888",""); unlock / cancel a contract first requires the parameters when decode is born into a contract to call list-unspent-outputs to get the generated contract information and get program."

The following is a related code snippet:

Param=new JSONObject (); param.put ("id", outputid); param.put ("smart_contract", true); sendHttpPost (param.toString (), "list-unspent-outputs", "http://127.0.0.1:9888","");" call decode-program to get the generated contract parameter information

The following is a related code snippet:

Param=new JSONObject (); param.put ("program", program); sendHttpPost (param.toString (), "decode-program", "http://127.0.0.1:9888","");"

It should be noted that the values generated by decode are in reverse order (more on this later article).

To unlock / cancel is to remove the third step in the step of generating the contract and replace the parameters in step 4 of the generated contract.

The construction parameters for canceling the contract are as follows:

SpendAccountUnspentOutput = arguments: [{type: 'raw_tx_signature', / / generate pubkeylist details of step 2 of the contract raw_data: {derivation_path: pubkeylist.pubkey_infos [0] .derivation _ path, xpub: pubkeylist.root_xpub}} {type: 'data', raw_data: {/ / Parameter offset is fixed in a contract value:' 13000000'}], output_id: output_id Type: 'spend_account_unspent_output'} const controlAction = {type:' control_program', amount: 100000000, asset_id: asset_id Control_program:control_program} const gasAction = {type: 'spend_account', account_id:account_id, asset_alias:' BTM', amount: 50000000}

The parameters for executing the contract are as follows:

Const spendAccountUnspentOutput = {arguments: [{type: 'data', raw_data: {/ / 00000000 refers to the first clause and indicates direct execution No need to jump to value: '00000000'}], output_id: output_id, type:' spend_account_unspent_output'} / / assets provided by contract execution const issueControlAction = {control_program: control_program Amount: 100000000, asset_id: asset_id, type: 'control_program'} / / assets provided by contract execution const issueSpendAction = {account_id: account_id, amount: 100000000, asset_id: asset_id Type: 'spend_account'} / / miner's fee const gasAction = {type:' spend_account', account_id: account_id, asset_alias: 'BTM' Amount: 50000000} / / contract execution obtains asset object const controlAction = {type: 'control_program', amount: 100000000, asset_id: asset_id, control_program: compileData.control_program}

Build operation is actually the process of specifying input and output. For more information, please see the official build document and the official api document.

Remarks

The call is based on the original okhttp API javautil as follows:

Public static String sendHttpPost (String bodyStr,String method,String bytomApiserverUrl,String bytomApiserverToken) throws IOException {OkHttpClient client = new OkHttpClient (); MediaType mediaType = MediaType.parse ("application/json"); RequestBody body = RequestBody.create (mediaType, bodyStr) Request request = new Request.Builder () .url (bytomApiserverUrl+ "/" + method) .post (body) .addHeader ("cache-control", "no-cache") .addHeader ("Connection", "close") .build () If (bytomApiserverUrl==null | | bytomApiserverUrl.contains ("127.0.0.1") | | bytomApiserverUrl.contains ("localhost") {} else {byte [] encodedAuth = Base64.encodeBase64 (bytomApiserverToken.getBytes ("US-ASCII")); String authHeader = "Basic" + new String (encodedAuth) Request = new Request.Builder () .url (bytomApiserverUrl+ "/" + method) .post (body) .addHeader ("authorization", authHeader) .addHeader ("cache-control", "no-cache") .addHeader ("Connection", "close") .build () } Response response = client.newCall (request). Execute (); return response.body (). String ();} at this point, the study of "how to lock a contract in bytom" is over. I hope to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 293

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report