forked from FISCO-BCOS/web3sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request FISCO-BCOS#316 from FISCO-BCOS/feature-txdecode
add input/output/event decode.
- Loading branch information
Showing
39 changed files
with
8,785 additions
and
39 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
contract TableFactory { | ||
function openTable(string) public constant returns (Table); //open table | ||
function createTable(string,string,string) public returns(int); //create table | ||
} | ||
|
||
//select condition | ||
contract Condition { | ||
function EQ(string, int) public; | ||
function EQ(string, string) public; | ||
|
||
function NE(string, int) public; | ||
function NE(string, string) public; | ||
|
||
function GT(string, int) public; | ||
function GE(string, int) public; | ||
|
||
function LT(string, int) public; | ||
function LE(string, int) public; | ||
|
||
function limit(int) public; | ||
function limit(int, int) public; | ||
} | ||
|
||
//one record | ||
contract Entry { | ||
function getInt(string) public constant returns(int); | ||
function getAddress(string) public constant returns(address); | ||
function getBytes64(string) public constant returns(byte[64]); | ||
function getBytes32(string) public constant returns(bytes32); | ||
|
||
function set(string, int) public; | ||
function set(string, string) public; | ||
} | ||
|
||
//record sets | ||
contract Entries { | ||
function get(int) public constant returns(Entry); | ||
function size() public constant returns(int); | ||
} | ||
|
||
//Table main contract | ||
contract Table { | ||
//select api | ||
function select(string, Condition) public constant returns(Entries); | ||
//insert api | ||
function insert(string, Entry) public returns(int); | ||
//update api | ||
function update(string, Entry, Condition) public returns(int); | ||
//remove api | ||
function remove(string, Condition) public returns(int); | ||
|
||
function newEntry() public constant returns(Entry); | ||
function newCondition() public constant returns(Condition); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
import "./Table.sol"; | ||
|
||
contract TableTest { | ||
event CreateResult(int count); | ||
event InsertResult(int count, string name, bytes8 item_name, bytes32[] item_id); | ||
event UpdateResult(int count, string name); | ||
event RemoveResult(int count); | ||
|
||
//create table | ||
function create() public returns(int){ | ||
TableFactory tf = TableFactory(0x1001); //The fixed address is 0x1001 for TableFactory | ||
|
||
int count = tf.createTable("t_test", "name", "item_id,item_name"); | ||
emit CreateResult(count); | ||
return count; | ||
} | ||
|
||
//select records | ||
function select(string name) public constant returns(bytes32[], int[], bytes32[]){ | ||
TableFactory tf = TableFactory(0x1001); | ||
Table table = tf.openTable("t_test"); | ||
|
||
Condition condition = table.newCondition(); | ||
|
||
Entries entries = table.select(name, condition); | ||
bytes32[] memory user_name_bytes_list = new bytes32[](uint256(entries.size())); | ||
int[] memory item_id_list = new int[](uint256(entries.size())); | ||
bytes32[] memory item_name_bytes_list = new bytes32[](uint256(entries.size())); | ||
|
||
for(int i=0; i<entries.size(); ++i) { | ||
Entry entry = entries.get(i); | ||
|
||
user_name_bytes_list[uint256(i)] = entry.getBytes32("name"); | ||
item_id_list[uint256(i)] = entry.getInt("item_id"); | ||
item_name_bytes_list[uint256(i)] = entry.getBytes32("item_name"); | ||
} | ||
|
||
return (user_name_bytes_list, item_id_list, item_name_bytes_list); | ||
} | ||
//insert records | ||
function insert(string name, int item_id, string item_name) public returns(int result, string result_name, bytes32, address addr, bytes32[]) { | ||
TableFactory tf = TableFactory(0x1001); | ||
Table table = tf.openTable("t_test"); | ||
|
||
Entry entry = table.newEntry(); | ||
entry.set("name", name); | ||
entry.set("item_id", item_id); | ||
entry.set("item_name", item_name); | ||
|
||
int count = table.insert(name, entry); | ||
|
||
bytes32[] memory bytes_list = new bytes32[](uint256(2)); | ||
bytes_list[0] = "fisco"; | ||
bytes_list[1] = "bcos"; | ||
|
||
emit InsertResult(count, "fruit", "apple", bytes_list); | ||
emit UpdateResult(count, "fruit"); | ||
|
||
return (count, "hello", "world", 0x12, bytes_list); | ||
} | ||
//update records | ||
function update(string name, int item_id, string item_name) public returns(int) { | ||
TableFactory tf = TableFactory(0x1001); | ||
Table table = tf.openTable("t_test"); | ||
|
||
Entry entry = table.newEntry(); | ||
entry.set("item_name", item_name); | ||
|
||
Condition condition = table.newCondition(); | ||
condition.EQ("name", name); | ||
condition.EQ("item_id", item_id); | ||
|
||
int count = table.update(name, entry, condition); | ||
emit UpdateResult(count, "fruit"); | ||
|
||
return count; | ||
} | ||
//remove records | ||
function remove(string name, int item_id) public returns(int){ | ||
TableFactory tf = TableFactory(0x1001); | ||
Table table = tf.openTable("t_test"); | ||
|
||
Condition condition = table.newCondition(); | ||
condition.EQ("name", name); | ||
condition.EQ("item_id", item_id); | ||
|
||
int count = table.remove(name, condition); | ||
emit RemoveResult(count); | ||
|
||
return count; | ||
} | ||
} |
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
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
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
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
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
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
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
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
Oops, something went wrong.