bitshares研究系列【custom operation】

在Bitshares中看到有个叫“custom_operation”的,来看一下这个是干什么的?

custom_operation定义

custom.hpp

   struct custom_operation : public base_operation
   {
      struct fee_parameters_type { 
         uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; 
         uint32_t price_per_kbyte = 20000;
      };

      asset                     fee;
      account_id_type           payer;
      flat_set<account_id_type> required_auths;
      uint16_t                  id = 0;
      vector<char>              data;

      account_id_type   fee_payer()const { return payer; }
      void              validate()const;
      share_type        calculate_fee(const fee_parameters_type& k)const;
   };

custom_operation交易

再来通过cli_wallet的建立operation,先取得operation的数据格式,如下:

get_prototype_operation custom_operation
[
  35,{
    "fee": {
      "amount": 0,
      "asset_id": "1.3.0"
    },
    "payer": "1.2.0",
    "required_auths": [],
    "id": 0,
    "data": ""
  }
]

手动建立交易4步曲:

1、

unlocked >>> begin_builder_transaction
begin_builder_transaction
0

2、

unlocked >>> add_operation_to_builder_transaction 0 [35,{"fee": {"amount": 0,"asset_id":"1.3.0"},"payer": "1.2.31","required_auths": [],"id": 9999,"data": ""}]
add_operation_to_builder_transaction 0 [35,{"fee": {"amount": 0,"asset_id":"1.3.0"},"payer": "1.2.31","required_auths": [],"id": 9999,"data": ""}]
null

3、

unlocked >>> set_fees_on_builder_transaction 0 BTS
set_fees_on_builder_transaction 0 BTS
{
  "amount": 100273,
  "asset_id": "1.3.0"
}

4、

unlocked >>> sign_builder_transaction 0 true
sign_builder_transaction 0 true
{
  "ref_block_num": 58488,
  "ref_block_prefix": 422249092,
  "expiration": "2018-08-02T08:43:12",
  "operations": [[
      35,{
        "fee": {
          "amount": 100273,
          "asset_id": "1.3.0"
        },
        "payer": "1.2.31",
        "required_auths": [],
        "id": 9999,
        "data": ""
      }
    ]
  ],
  "extensions": [],
  "signatures": [
    "2024c3b603d1fec11d2d206f5c75873560ae832a33e5436055abdb29a5786399386dc2e5f488f24e34c76fc6a8f083d1641e41d3f59eb9a21abfd4991a61eb609d"
  ]
}

custom_operation做什么用?

想到几个地方可以用上:

  1. 用data来构造一些数据结构,链可以解析数据结构做处理,相当于有了一个子集
  2. data用来存储数据,例如想存储一些数据,可以把数据加密后放在data字段中,通过发送这个交易能记录到块上,以后也可以取这个块并解密,而不必记到其它地方了;
  3. 用这个交易做签名验证,例如用户是否拥有对应私钥,如果签名过了则私钥正确。

感谢您阅读 @chaimyu 的帖子,期待您能留言交流!

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center