Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync code into dev #336

Merged
merged 35 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4d003a3
Merge pull request #287 from FISCO-BCOS/release-2.0.0-rc3
fqliao May 30, 2019
ded8c41
Revert "Release 2.0.0 rc3"
JimmyShi22 May 30, 2019
c6ce1d3
Merge pull request #288 from FISCO-BCOS/revert-287-release-2.0.0-rc3
JimmyShi22 May 30, 2019
6621ed4
Revert "Revert "Release 2.0.0 rc3""
bxq2011hust Jun 4, 2019
51f062f
Merge pull request #293 from FISCO-BCOS/release-2.0.0-rc3
bxq2011hust Jun 5, 2019
3783c7b
Merge pull request #300 from fqliao/release-2.0.0-rc3
fqliao Jun 12, 2019
9054e6a
Merge pull request #303 from fqliao/release-2.0.0-rc3
fqliao Jun 13, 2019
38c4a7f
Merge pull request #307 from FISCO-BCOS/release-2.0.0-rc3
bxq2011hust Jun 13, 2019
43a732e
make receipt error more friendly and format code
vita-dounai Jun 13, 2019
3f8debd
Merge pull request #292 from FISCO-BCOS/revert-288-revert-287-release…
bxq2011hust Jun 13, 2019
bc4aa23
update version in file release_node.txt
ywy2090 Jun 17, 2019
616bf27
Merge pull request #319 from ywy2090/fisco-master
ywy2090 Jun 17, 2019
bfc12aa
update version in filerelease_node.txt (#318)
ywy2090 Jun 17, 2019
f21ea53
Merge pull request #324 from FISCO-BCOS/dev
bxq2011hust Jun 24, 2019
96af231
fix conflict between master and release-2.0.4
vita-dounai Jul 3, 2019
a767255
update .travis.yml
vita-dounai Jul 3, 2019
64dd45d
Merge pull request #329 from vita-dounai/master
bxq2011hust Jul 3, 2019
6bfcd16
add indexed parameters for event.
ywy2090 Jun 25, 2019
229467b
fix conficts
fqliao Jul 4, 2019
7138e73
add guomi TableTest test class
fqliao Jun 24, 2019
1049524
remove useless file
fqliao Jun 24, 2019
42c7c90
update .gitignore
fqliao Jun 24, 2019
ab0a1ca
remove useless test
fqliao Jun 24, 2019
3b2a90a
move guomi TableTest
fqliao Jun 24, 2019
6a2314c
remove password parameter for some method for P12Manager
fqliao Jun 24, 2019
eba6483
add create(ECKeyPair keyPair) for GenCredential
fqliao Jun 24, 2019
20042ab
fix codacy
fqliao Jun 25, 2019
6f6eef1
rename CRUDSerivce to CRUDService
fqliao Jun 25, 2019
e0c23c4
fix conficts
fqliao Jul 4, 2019
e61664a
fix conficts
fqliao Jul 4, 2019
2d463f3
fix codacy
fqliao Jun 26, 2019
ff7fba5
update travis ci
fqliao Jul 4, 2019
0225e02
fix ut
fqliao Jul 4, 2019
f0abd40
update ChangeLog and web3sdk version.
ywy2090 Jul 4, 2019
bfc983b
resolve conflicts
bxq2011hust Jul 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix conficts
  • Loading branch information
fqliao authored and bxq2011hust committed Jul 4, 2019
commit e0c23c48c4e5992ead50a5e63b9b55c4f425852a
57 changes: 57 additions & 0 deletions solidity/Table.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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 getString(string) public constant returns(string);

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);
}
89 changes: 89 additions & 0 deletions solidity/TableTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2;

import "./Table.sol";

contract TableTest {
event CreateResult(int count);
event InsertResult(int count);
event UpdateResult(int count);
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(string[], int[], string[]){
TableFactory tf = TableFactory(0x1001);
Table table = tf.openTable("t_test");

Condition condition = table.newCondition();

Entries entries = table.select(name, condition);
string[] memory user_name_bytes_list = new string[](uint256(entries.size()));
int[] memory item_id_list = new int[](uint256(entries.size()));
string[] memory item_name_bytes_list = new string[](uint256(entries.size()));

for(int i=0; i<entries.size(); ++i) {
Entry entry = entries.get(i);

user_name_bytes_list[uint256(i)] = entry.getString("name");
item_id_list[uint256(i)] = entry.getInt("item_id");
item_name_bytes_list[uint256(i)] = entry.getString("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) {
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);
emit InsertResult(count);

return count;
}
//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);

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;
}
}
2 changes: 1 addition & 1 deletion src/integration-test/java/org/fisco/bcos/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void setUpBeforeClass() throws Exception {
context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

Service service = context.getBean(Service.class);
service.run();
service.run();

ChannelEthereumService channelEthereumService = new ChannelEthereumService();
channelEthereumService.setChannelService(service);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public static List<TypeReference<?>> paramFormat(List<NamedType> paramTypes)

for (int i = 0; i < paramTypes.size(); i++) {

AbiDefinition.NamedType.Type type = new AbiDefinition.NamedType.Type(paramTypes.get(i).getType());
AbiDefinition.NamedType.Type type =
new AbiDefinition.NamedType.Type(paramTypes.get(i).getType());
// nested array , not support now.
if (type.getDepth() > 1) {
throw new BaseException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
import org.fisco.bcos.web3j.abi.datatypes.Type;

public class EventResultEntity extends ResultEntity {

public EventResultEntity(String name, String type, boolean indexed, Type data) {
super(name, type, data);

this.setIndexed(indexed);
}

private boolean indexed;

public boolean isIndexed() {
Expand All @@ -19,4 +12,10 @@ public boolean isIndexed() {
public void setIndexed(boolean indexed) {
this.indexed = indexed;
}

public EventResultEntity(String name, String type, boolean indexed, Type data) {
super(name, type, data);

this.setIndexed(indexed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class TransactionDecoder {
private Map<String, AbiDefinition> methodIDMap;

public TransactionDecoder(String abi) {
this(abi, "");
this(abi, "");
}

public TransactionDecoder(String abi, String bin) {
Expand All @@ -45,13 +45,13 @@ public TransactionDecoder(String abi, String bin) {
methodIDMap.put(methodID, abiDefinition);
}
}

private String addHexPrefixToString(String s) {
if(!s.startsWith("0x")) {
return "0x" + s;
}
return s;
if (!s.startsWith("0x")) {
return "0x" + s;
}

return s;
}

/**
Expand All @@ -63,22 +63,15 @@ private String addHexPrefixToString(String s) {
*/
public String decodeInputReturnJson(String input)
throws JsonProcessingException, TransactionException, BaseException {
input = addHexPrefixToString(input);

input = addHexPrefixToString(input);

// select abi
AbiDefinition abiFunc = selectAbiDefinition(input);

// decode input
List<ResultEntity> resultList = decodeInputReturnObject(input);

Map<String, Object> resultMap = decodeInputReturnObject(input);
// format result to json
Map<String, Object> resultMap = new LinkedHashMap<>();
String methodSign = decodeMethodSign(abiFunc);
resultMap.put("function", methodSign);
resultMap.put("methodID", FunctionEncoder.buildMethodId(methodSign));
resultMap.put("data", resultList);

String result = ObjectMapperFactory.getObjectMapper().writeValueAsString(resultMap);

return result;
Expand All @@ -90,11 +83,11 @@ public String decodeInputReturnJson(String input)
* @throws BaseException
* @throws TransactionException
*/
public List<ResultEntity> decodeInputReturnObject(String input)
public Map<String, Object> decodeInputReturnObject(String input)
throws BaseException, TransactionException {
input = addHexPrefixToString(input);

input = addHexPrefixToString(input);

// select abi
AbiDefinition abiDefinition = selectAbiDefinition(input);

Expand All @@ -114,7 +107,14 @@ public List<ResultEntity> decodeInputReturnObject(String input)
inputTypes.get(i).getType(),
resultType.get(i)));
}
return resultList;

Map<String, Object> resultMap = new LinkedHashMap<>();
String methodSign = decodeMethodSign(abiDefinition);
resultMap.put("function", methodSign);
resultMap.put("methodID", FunctionEncoder.buildMethodId(methodSign));
resultMap.put("data", resultList);

return resultMap;
}

/**
Expand All @@ -128,8 +128,9 @@ public List<ResultEntity> decodeInputReturnObject(String input)
public String decodeOutputReturnJson(String input, String output)
throws JsonProcessingException, BaseException, TransactionException {

List<ResultEntity> resultList = decodeOutputReturnObject(input, output);
String result = ObjectMapperFactory.getObjectMapper().writeValueAsString(resultList);
Map<String, Object> resultMap = decodeOutputReturnObject(input, output);

String result = ObjectMapperFactory.getObjectMapper().writeValueAsString(resultMap);
return result;
}

Expand All @@ -140,10 +141,11 @@ public String decodeOutputReturnJson(String input, String output)
* @throws TransactionException
* @throws BaseException
*/
public List<ResultEntity> decodeOutputReturnObject(String input, String output)
public Map<String, Object> decodeOutputReturnObject(String input, String output)
throws TransactionException, BaseException {

output = addHexPrefixToString(output);

input = addHexPrefixToString(input);
output = addHexPrefixToString(output);

// select abi
AbiDefinition abiDefinition = selectAbiDefinition(input);
Expand All @@ -163,7 +165,14 @@ public List<ResultEntity> decodeOutputReturnObject(String input, String output)
outputTypes.get(i).getType(),
resultType.get(i)));
}
return resultList;

Map<String, Object> resultMap = new LinkedHashMap<>();
String methodSign = decodeMethodSign(abiDefinition);
resultMap.put("function", methodSign);
resultMap.put("methodID", FunctionEncoder.buildMethodId(methodSign));
resultMap.put("data", resultList);

return resultMap;
}

/**
Expand Down Expand Up @@ -273,7 +282,7 @@ public Tuple2<AbiDefinition, List<EventResultEntity>> decodeEventReturnObject(Lo
indexedInputs.get(i).getType(),
true,
eventValued.getIndexedValues().get(i));

resultEntityList.add(eventEntity);
}

Expand All @@ -284,7 +293,7 @@ public Tuple2<AbiDefinition, List<EventResultEntity>> decodeEventReturnObject(Lo
nonIndexedInputs.get(i).getType(),
false,
eventValued.getNonIndexedValues().get(i));

resultEntityList.add(eventEntity);
}

Expand Down
60 changes: 14 additions & 46 deletions src/test/java/org/fisco/bcos/web3j/tx/txdecode/TableTest.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void main(String[] args) throws Exception {
System.out.println("===================decode input===================");
String input = txReceipt.getInput();
String inputResult1 = transactionDecoder.decodeInputReturnJson(input);
List<ResultEntity> inputResult2 = transactionDecoder.decodeInputReturnObject(input);
Map<String, Object> inputResult2 = transactionDecoder.decodeInputReturnObject(input);

System.out.println(inputResult1);
System.out.println(inputResult2);
Expand All @@ -38,7 +38,8 @@ public static void main(String[] args) throws Exception {
System.out.println("===================decode output===================");
String output = txReceipt.getOutput();
String outputResult1 = transactionDecoder.decodeOutputReturnJson(input, output);
List<ResultEntity> outputResult2 =

Map<String, Object> outputResult2 =
transactionDecoder.decodeOutputReturnObject(input, output);

System.out.println(outputResult1);
Expand Down
Loading