EOS系列三:关于ABI文件

1、简介

eos开发工具包eosio.cdt中的eosio-cpp可以根据合约代码自动生成abi文件,但在某些情况下(一些C++高级特性的使用以及某些自定义类型的使用),自动生成失败,则需要了解abi文件的工作机制,以便debug你的代码。

其实abi文件就是用JSON格式进行合约的结构描述,包括合约代码中定义的数据类型、执行函数等。

2、ABI文件格式为JSON,主要结构如下:

 


{
   "version": "eosio::abi/1.0",
   "types": [],
   "structs": [],
   "actions": [],
   "tables": [],
   "ricardian_clauses": [],
   "abi_extensions": [],
   "___comment" : ""
}

2.1Types,对象数组,其中对象格式:

{
   "new_type_name": "name",
   "type": "name"
}

2.2Structs,对象数组,其中对象格式:

{
   "name": "issue", //The name 
   "base": "", 			//Inheritance, parent struct
   "fields": []			//Array of field objects describing the struct's fields. 
}

2.2.1Fields,对象数组,其中对象格式:

{
   "name":"", // The field's name
   "type":""   // The field's type
}  

2.3Actions

{
  "name": "transfer", 			//The name of the action as defined in the contract
  "type": "transfer", 			//The name of the implicit struct as described in the ABI
  "ricardian_contract": "" 	//An optional ricardian clause to associate to this action describing its intended functionality.
}

 

2.4Tables

{
  "name": "",       //The name of the table, determined during instantiation. 
  "type": "", 			//The table's corresponding struct
  "index_type": "", //The type of primary index of this table
  "key_names" : [], //An array of key names, length must equal length of key_types member
  "key_types" : []  //An array of key types that correspond to key names array member, length of array must equal length of key names array.
}

 

 

 

 

 

 

 

你可能感兴趣的:(EOS区块链)