Skip to content

Commit 8cebaee

Browse files
committed
Merge branch 'feature/contract' of github.com:ChainSQL/java-chainsql-api into feature/contract
2 parents df94722 + e6b0e66 commit 8cebaee

File tree

5 files changed

+61
-42
lines changed

5 files changed

+61
-42
lines changed

chainsql/src/main/java/com/peersafe/chainsql/core/Chainsql.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ public Ripple accountSet(int nFlag, boolean bSet)
854854
* @param transferFeeMax decimal number string
855855
* @return You can use this to call other Ripple functions continually.
856856
*/
857-
public Ripple accountSet(String transferRate, String transferFeeMin, String transferFeeMax)
857+
public Ripple accountSet(String transferRate, String transferFeeMin, String transferFeeMax) throws Exception
858858
{
859859
Ripple ripple = new Ripple(this);
860860
return ripple.accountSet(transferRate, transferFeeMin, transferFeeMax);

chainsql/src/main/java/com/peersafe/chainsql/core/Ripple.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private Ripple pay(String accountId,Amount amount){
103103
//
104104
if((null!=feeMin) || (null!=feeMax) || lFeeRate != 0)
105105
{
106-
if( (!feeMin.isEmpty()) && feeMin.equals(feeMax) )
106+
if( null != feeMin && !feeMin.isEmpty() && feeMin.equals(feeMax) )
107107
{
108108
value = value.add(new BigDecimal(feeMin));
109109
}
@@ -330,51 +330,56 @@ public Ripple accountSet(int nFlag, boolean bSet)
330330
* @param transferFeeMax decimal number string
331331
* @return You can use this to call other Ripple functions continually.
332332
*/
333-
public Ripple accountSet(String transferRate, String transferFeeMin, String transferFeeMax)
333+
public Ripple accountSet(String transferRate, String transferFeeMin, String transferFeeMax) throws Exception
334334
{
335335
//
336336
double rate = 1.0;double feeMin;double feeMax;
337-
try {
337+
// try {
338338
rate = Double.parseDouble(transferRate);
339339
if((rate != 0) && rate<1.0 || rate>2.0)
340340
{
341-
Client.logger.log(Level.WARNING, "TransferRate must be 0 or a number >= 1.0 && <= 2.0");
342-
return null;
341+
throw new Exception("TransferRate must be 0 or a number >= 1.0 && <= 2.0");
342+
// Client.logger.log(Level.WARNING, "TransferRate must be 0 or a number >= 1.0 && <= 2.0");
343+
// return null;
343344
}
344345
feeMin = Double.parseDouble(transferFeeMin);
345346
feeMax = Double.parseDouble(transferFeeMax);
346347
if(feeMin < 0 || feeMax <0)
347348
{
348-
Client.logger.log(Level.WARNING, "min or max cannot be less than 0");
349-
return null;
349+
throw new Exception("min or max cannot be less than 0");
350+
// Client.logger.log(Level.WARNING, "min or max cannot be less than 0");
351+
// return null;
350352
}
351353
if(feeMin > feeMax)
352354
{
353-
Client.logger.log(Level.WARNING, "min cannot be greater than max");
354-
return null;
355+
throw new Exception("min cannot be greater than max");
356+
// Client.logger.log(Level.WARNING, "min cannot be greater than max");
357+
// return null;
355358
}
356359
//
357360
if(feeMin == feeMax && feeMin>0)
358361
{
359362
if(rate>PRECISION && rate-1.0 > PRECISION)
360363
{
361-
Client.logger.log(Level.WARNING, "fee mismatch transferRate");
362-
return null;
364+
throw new Exception("fee mismatch transferRate");
365+
// Client.logger.log(Level.WARNING, "fee mismatch transferRate");
366+
// return null;
363367
}
364368
}
365369
if(feeMin < feeMax) {
366370
if(rate<PRECISION || rate-1.0 < PRECISION)
367371
{
368-
Client.logger.log(Level.WARNING, "fee mismatch transferRate");
369-
return null;
372+
throw new Exception("fee mismatch transferRate");
373+
// Client.logger.log(Level.WARNING, "fee mismatch transferRate");
374+
// return null;
370375
}
371376
}
372-
}
373-
catch(Exception e)
374-
{
375-
Client.logger.log(Level.WARNING, e + "\nTransferRate must be a number >= 1.0 && <= 2.0; TransferFeeMin and TransferFeeMax must be decimal number string.");
376-
return null;
377-
}
377+
// }
378+
// catch(Exception e)
379+
// {
380+
// Client.logger.log(Level.WARNING, e + "\nTransferRate must be a number >= 1.0 && <= 2.0; TransferFeeMin and TransferFeeMax must be decimal number string.");
381+
// return null;
382+
// }
378383
transferRate = transferRate.replace(".", "");
379384
int nLen = 10 - transferRate.length();
380385
while (nLen>0)

chainsql/src/test/java/com/peersafe/example/chainsql/TestRipple.java

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,45 @@
77
import com.peersafe.chainsql.core.Chainsql;
88
import com.peersafe.chainsql.core.Submit.SyncCond;
99

10+
import java.nio.channels.ScatteringByteChannel;
11+
1012
public class TestRipple {
1113

1214
public static final Chainsql c = new Chainsql();
1315
//
1416
//account,secret
1517
private static String[] sAddr = {
16-
"zHb9CJAWyB4zj91VRWn96DkukG4bwdtyTh", // 0
17-
"zKQwdkkzpUQC9haHFEe2EwUsKHvvwwPHsv", // 1
18-
"zPcimjPjkhQk7a7uFHLKEv6fyGHwFGQjHa", // 2
19-
"z4ypskpHPpMDtHsZvFHg8eDEdTjQrYYYV6" // 3
18+
"zHb9CJAWyB4zj91VRWn96DkukG4bwdtyTh", // root
19+
"zLLV3G8RfBXY4EAYDvnSaAz4q4PQg8PEe6", // user1
20+
"zPcimjPjkhQk7a7uFHLKEv6fyGHwFGQjHa", // user
21+
"zhRc343nqZk1wUEQFGXaoU76faJgYRrSBS" // issuer
2022

2123
};
2224
private static String[] sSec = {
23-
"xnoPBzXtMeMyMHUVTgbuqAfg1SUTb", // 0
24-
"xnJn5J5uYz3qnYX72jXkAPVB3ZsER", // 1
25-
"xxCosoAJMADiy6kQFVgq1Nz8QewkU", // 2
26-
"xxXvas5HTwVwjpmGNLQDdRyYe2H6t" // 3
25+
"xnoPBzXtMeMyMHUVTgbuqAfg1SUTb", // root sec
26+
"xnBWT67xXecGGWPCrTYtE1MHjKQqW", // user1 sec
27+
"xxCosoAJMADiy6kQFVgq1Nz8QewkU", // user sec
28+
"xxRjxBvT7ABczPh2CMikpNUwjiuLU" // issuer sec
2729

2830
};
2931
public static String rootAddress = sAddr[0];
3032
public static String rootSecret = sSec[0];
33+
3134
public static String sUser1 = sAddr[1];
3235
public static String sUserSec1 = sSec[1];
3336
public static String sUser = sAddr[2];
3437
public static String sUserSec = sSec[2];
38+
3539
public static String sGateWay = sAddr[3];
3640
public static String sGateWaySec = sSec[3];
3741

3842
//
3943
public static void main(String[] args) throws Exception
4044
{
4145
//
42-
c.connect("ws://127.0.0.1:6006");
46+
c.connect("ws://192.168.29.115:5217");
4347
//
44-
String sCurrency = "aaa";
48+
String sCurrency = "abc";
4549
JSONObject jsonObj;
4650
boolean bGateWay = true;
4751
boolean bEscrow = false;
@@ -50,9 +54,9 @@ public static void main(String[] args) throws Exception
5054
//
5155
c.as(rootAddress, rootSecret);
5256
//
53-
boolean bActive = true;
57+
boolean bActive = false;
5458
boolean bTrust = true;
55-
boolean bPay = true;
59+
boolean bPay = false;
5660
if(bActive)
5761
{
5862
System.out.print("activate >>>>>>>>>>>>>>>\n");
@@ -70,8 +74,14 @@ public static void main(String[] args) throws Exception
7074
c.as(sGateWay, sGateWaySec);
7175
jsonObj = c.accountSet(8, true).submit(SyncCond.validate_success);
7276
System.out.print("set gateWay:" + jsonObj + "\ntrust gateWay ...\n");
73-
jsonObj = c.accountSet("1.005", "0.2", "0.3").submit(SyncCond.validate_success);
74-
System.out.print("set gateWay:" + jsonObj + "\ntrust gateWay ...\n");
77+
try {
78+
jsonObj = c.accountSet("1.002", "0.2", "0.3").submit(SyncCond.validate_success);
79+
System.out.print("set gateWay:" + jsonObj + "\ntrust gateWay ...\n");
80+
}
81+
catch (Exception e)
82+
{
83+
System.out.print(e);
84+
}
7585
c.as(sUser, sUserSec);
7686
jsonObj = c.trustSet("1000000000", sCurrency, sGateWay).submit(SyncCond.validate_success);
7787
System.out.print(" user: " + jsonObj + "\n");
@@ -96,7 +106,7 @@ public static void main(String[] args) throws Exception
96106
jsonObj = c.connection.client.GetAccountLines(sUser);
97107
System.out.print(" lines: " + jsonObj + "\n");
98108
c.as(sUser, sUserSec);
99-
jsonObj = c.pay(sUser1, "10000", sCurrency, sGateWay).submit(SyncCond.validate_success);
109+
jsonObj = c.pay(sUser1, "10000000", sCurrency, sGateWay).submit(SyncCond.validate_success);
100110
System.out.print(" user1:\n " + jsonObj + "\n");
101111
jsonObj = c.connection.client.GetAccountLines(sUser1);
102112
System.out.print(" lines: " + jsonObj + "\n");
@@ -109,11 +119,14 @@ public static void main(String[] args) throws Exception
109119
boolean bTestFin = true;
110120
boolean bTestCancel = false;
111121
boolean bTime = false;
112-
int nCreateEscrowSeq = 41;
122+
int nCreateEscrowSeq = 2;
113123
if(bTestCreate)
114124
{
115-
c.as(sUser, sUserSec);
116-
jsonObj = c.escrowCreate(sUser1, "100", sCurrency, sGateWay, "2018-09-12 16:42:00", "2018-09-12 16:43:00").submit(SyncCond.validate_success);
125+
c.as(sGateWay, sGateWaySec);
126+
// jsonObj = c.escrowCreate(sUser1, "10", "", "2020-01-03 18:10:40").submit(SyncCond.validate_success);
127+
jsonObj = c.escrowCreate(sUser1, "10", "2020-01-03 17:27:06", "2020-01-03 18:10:40").submit(SyncCond.validate_success);
128+
// jsonObj = c.escrowCreate(sUser1, "10", sCurrency, sGateWay, "", "2020-01-03 16:17:56").submit(SyncCond.validate_success);
129+
// jsonObj = c.escrowCreate(sUser1, "10", sCurrency, sGateWay, "2018-09-12 16:42:00", "2018-09-12 16:43:00").submit(SyncCond.validate_success);
117130
System.out.print("escrowCreate res: " + jsonObj + "\n");
118131
jsonObj = c.getTransaction(jsonObj.getString("tx_hash"));
119132
nCreateEscrowSeq = jsonObj.getInt("Sequence");
@@ -123,7 +136,7 @@ public static void main(String[] args) throws Exception
123136
if(bTestFin)
124137
{
125138
c.as(sUser1, sUserSec1);
126-
jsonObj = c.escrowExecute(sUser, nCreateEscrowSeq).submit(SyncCond.validate_success);
139+
jsonObj = c.escrowExecute(sGateWay, nCreateEscrowSeq).submit(SyncCond.validate_success);
127140
System.out.print("escrowExecute res: " + jsonObj + "\n");
128141
}
129142
if(bTestCancel)
@@ -134,7 +147,7 @@ public static void main(String[] args) throws Exception
134147
}
135148
if(bTime)
136149
{
137-
System.out.print("\n" + RippleDate.localFromSecondsSinceRippleEpoch(590056740) + "\n");
150+
System.out.print("\n" + RippleDate.localFromSecondsSinceRippleEpoch(631346404) + "\n");
138151
System.exit(1);
139152
}
140153
System.exit(1);

codegen/codegen_chainsql.jar

30 Bytes
Binary file not shown.

codegen/src/main/java/com/peersafe/codegen/SolidityFunctionWrapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ private void buildConstantFunctionAsync(
825825

826826
ParameterizedTypeName typeName = ParameterizedTypeName.get(
827827
ClassName.get(Callback.class), nativeReturnTypeName);
828-
methodBuilder.addParameter(typeName,CALLBACK);
828+
829+
methodBuilder.addParameter(typeName,CALLBACK,Modifier.FINAL);
829830

830831
methodBuilder.addStatement("final $T function = "
831832
+ "new $T($N, \n$T.<$T>asList($L), "
@@ -920,7 +921,7 @@ Function.class, Function.class, funcNameToConst(functionName),
920921
methodBuilder, functionName, inputParams, outputParameterTypes);
921922

922923
methodBuilder.addParameter(ParameterizedTypeName.get(
923-
ClassName.get(Callback.class), parameterizedTupleType),CALLBACK);
924+
ClassName.get(Callback.class), parameterizedTupleType),CALLBACK,Modifier.FINAL);
924925

925926
buildTupleResultContainerAsync(methodBuilder, parameterizedTupleType, outputParameterTypes);
926927
}

0 commit comments

Comments
 (0)