@@ -0,0 +1,43 @@ | |||
package com.jd.blockchain.transaction; | |||
import java.util.concurrent.TimeUnit; | |||
import java.util.concurrent.TimeoutException; | |||
public class BooleanValueHolder extends ValueHolderBase { | |||
BooleanValueHolder(ContractInvocation invocation) { | |||
super(invocation); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @return | |||
*/ | |||
public boolean get() { | |||
return (boolean) super.getValue(); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public boolean get(long timeout) throws TimeoutException { | |||
return get(timeout, TimeUnit.MILLISECONDS); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @param unit | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public boolean get(long timeout, TimeUnit unit) throws TimeoutException { | |||
return (boolean) super.getValue(timeout, unit); | |||
} | |||
} |
@@ -0,0 +1,43 @@ | |||
package com.jd.blockchain.transaction; | |||
import java.util.concurrent.TimeUnit; | |||
import java.util.concurrent.TimeoutException; | |||
public class ByteValueHolder extends ValueHolderBase { | |||
ByteValueHolder(ContractInvocation invocation) { | |||
super(invocation); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @return | |||
*/ | |||
public byte get() { | |||
return (byte) super.getValue(); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public byte get(long timeout) throws TimeoutException { | |||
return get(timeout, TimeUnit.MILLISECONDS); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @param unit | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public byte get(long timeout, TimeUnit unit) throws TimeoutException { | |||
return (byte) super.getValue(timeout, unit); | |||
} | |||
} |
@@ -0,0 +1,164 @@ | |||
package com.jd.blockchain.transaction; | |||
public class ContractReturnValue { | |||
private ContractReturnValue() { | |||
} | |||
/** | |||
* 解析合约方法调用的返回值; | |||
* <p> | |||
* 用法示例:<br> | |||
* <code> | |||
* import static com.jd.blockchain.transaction.ContractReturnValue.*; <p><p><p> | |||
* | |||
* | |||
* ValueHolder<String retnHolder = decode(contract.issue(assetKey, amount)); <br> | |||
* | |||
* PreparedTransaction prepTx = tx.prepare();<br> | |||
* prepTx.sign(userKey);<br> | |||
* prepTx.commit()<br><br> | |||
* | |||
* String retnValue = retnHolder.get(); //这是同步方法,会阻塞当前线程等待交易提交后返回结果;<br> | |||
* </code> | |||
* | |||
* @param <T> | |||
* @param call | |||
* @return | |||
*/ | |||
public static <T> ValueHolder<T> decode(T call) { | |||
ContractInvocation invocation = ContractInvocationStub.take(); | |||
return new ValueHolder<T>(invocation); | |||
} | |||
/** | |||
* 解析合约方法调用的返回值; | |||
* <p> | |||
* 用法示例:<br> | |||
* <code> | |||
* import static com.jd.blockchain.transaction.ContractReturnValue.*; <p><p><p> | |||
* | |||
* | |||
* LongValueHolder retnHolder = decode(contract.issue(assetKey, amount)); <br> | |||
* | |||
* PreparedTransaction prepTx = tx.prepare();<br> | |||
* prepTx.sign(userKey);<br> | |||
* prepTx.commit()<br><br> | |||
* | |||
* long retnValue = retnHolder.get(); //这是同步方法,会阻塞当前线程等待交易提交后返回结果;<br> | |||
* </code> | |||
* | |||
* @param call | |||
* @return | |||
*/ | |||
public static LongValueHolder decode(long call) { | |||
ContractInvocation invocation = ContractInvocationStub.take(); | |||
return new LongValueHolder(invocation); | |||
} | |||
/** | |||
* 解析合约方法调用的返回值; | |||
* <p> | |||
* 用法示例:<br> | |||
* <code> | |||
* import static com.jd.blockchain.transaction.ContractReturnValue.*; <p><p><p> | |||
* | |||
* | |||
* IntValueHolder retnHolder = decode(contract.issue(assetKey, amount)); <br> | |||
* | |||
* PreparedTransaction prepTx = tx.prepare();<br> | |||
* prepTx.sign(userKey);<br> | |||
* prepTx.commit()<br><br> | |||
* | |||
* int retnValue = retnHolder.get(); //这是同步方法,会阻塞当前线程等待交易提交后返回结果;<br> | |||
* </code> | |||
* | |||
* @param call | |||
* @return | |||
*/ | |||
public static IntValueHolder decode(int call) { | |||
ContractInvocation invocation = ContractInvocationStub.take(); | |||
return new IntValueHolder(invocation); | |||
} | |||
/** | |||
* 解析合约方法调用的返回值; | |||
* <p> | |||
* 用法示例:<br> | |||
* <code> | |||
* import static com.jd.blockchain.transaction.ContractReturnValue.*; <p><p><p> | |||
* | |||
* | |||
* ShortValueHolder retnHolder = decode(contract.issue(assetKey, amount)); <br> | |||
* | |||
* PreparedTransaction prepTx = tx.prepare();<br> | |||
* prepTx.sign(userKey);<br> | |||
* prepTx.commit()<br><br> | |||
* | |||
* short retnValue = retnHolder.get(); //这是同步方法,会阻塞当前线程等待交易提交后返回结果;<br> | |||
* </code> | |||
* | |||
* @param call | |||
* @return | |||
*/ | |||
public static ShortValueHolder decode(short call) { | |||
ContractInvocation invocation = ContractInvocationStub.take(); | |||
return new ShortValueHolder(invocation); | |||
} | |||
/** | |||
* 解析合约方法调用的返回值; | |||
* <p> | |||
* 用法示例:<br> | |||
* <code> | |||
* import static com.jd.blockchain.transaction.ContractReturnValue.*; <p><p><p> | |||
* | |||
* | |||
* ByteValueHolder retnHolder = decode(contract.issue(assetKey, amount)); <br> | |||
* | |||
* PreparedTransaction prepTx = tx.prepare();<br> | |||
* prepTx.sign(userKey);<br> | |||
* prepTx.commit()<br><br> | |||
* | |||
* byte retnValue = retnHolder.get(); //这是同步方法,会阻塞当前线程等待交易提交后返回结果;<br> | |||
* </code> | |||
* | |||
* @param call | |||
* @return | |||
*/ | |||
public static ByteValueHolder decode(byte call) { | |||
ContractInvocation invocation = ContractInvocationStub.take(); | |||
return new ByteValueHolder(invocation); | |||
} | |||
/** | |||
* 解析合约方法调用的返回值; | |||
* <p> | |||
* 用法示例:<br> | |||
* <code> | |||
* import static com.jd.blockchain.transaction.ContractReturnValue.*; <p><p><p> | |||
* | |||
* | |||
* BooleanValueHolder retnHolder = decode(contract.issue(assetKey, amount)); <br> | |||
* | |||
* PreparedTransaction prepTx = tx.prepare();<br> | |||
* prepTx.sign(userKey);<br> | |||
* prepTx.commit()<br><br> | |||
* | |||
* boolean retnValue = retnHolder.get(); //这是同步方法,会阻塞当前线程等待交易提交后返回结果;<br> | |||
* </code> | |||
* | |||
* @param call | |||
* @return | |||
*/ | |||
public static BooleanValueHolder decode(boolean call) { | |||
ContractInvocation invocation = ContractInvocationStub.take(); | |||
return new BooleanValueHolder(invocation); | |||
} | |||
//----------------------- 内部类型 ----------------------- | |||
} |
@@ -1,418 +0,0 @@ | |||
package com.jd.blockchain.transaction; | |||
import java.util.concurrent.ExecutionException; | |||
import java.util.concurrent.TimeUnit; | |||
import java.util.concurrent.TimeoutException; | |||
public class ContractReturns { | |||
/** | |||
* 解析合约方法调用的返回值; | |||
* <p> | |||
* 用法示例:<br> | |||
* <code> | |||
* ReturnValue<String> retnHolder = decode(contract.issue(assetKey, amount)); | |||
* | |||
* PreparedTransaction prepTx = tx.prepare(); | |||
* prepTx.sign(userKey); | |||
* prepTx.commit() | |||
* | |||
* String retnValue = retnHolder.get(); //这是同步方法,会阻塞当前线程等待交易提交后返回结果; | |||
* </code> | |||
* | |||
* @param <T> | |||
* @param call | |||
* @return | |||
*/ | |||
public static <T> ReturnValue<T> decode(T call) { | |||
ContractInvocation invocation = ContractInvocationStub.take(); | |||
return new ReturnValue<T>(invocation); | |||
} | |||
/** | |||
* 解析合约方法调用的返回值; | |||
* <p> | |||
* 用法示例:<br> | |||
* <code> | |||
* ReturnLongValue retnHolder = decode(contract.issue(assetKey, amount)); | |||
* | |||
* PreparedTransaction prepTx = tx.prepare(); | |||
* prepTx.sign(userKey); | |||
* prepTx.commit() | |||
* | |||
* long retnValue = retnHolder.get(); //这是同步方法,会阻塞当前线程等待交易提交后返回结果; | |||
* </code> | |||
* | |||
* @param call | |||
* @return | |||
*/ | |||
public static ReturnLongValue decode(long call) { | |||
ContractInvocation invocation = ContractInvocationStub.take(); | |||
return new ReturnLongValue(invocation); | |||
} | |||
/** | |||
* 解析合约方法调用的返回值; | |||
* <p> | |||
* 用法示例:<br> | |||
* <code> | |||
* ReturnLongValue retnHolder = decode(contract.issue(assetKey, amount)); | |||
* | |||
* PreparedTransaction prepTx = tx.prepare(); | |||
* prepTx.sign(userKey); | |||
* prepTx.commit() | |||
* | |||
* int retnValue = retnHolder.get(); //这是同步方法,会阻塞当前线程等待交易提交后返回结果; | |||
* </code> | |||
* | |||
* @param call | |||
* @return | |||
*/ | |||
public static ReturnIntValue decode(int call) { | |||
ContractInvocation invocation = ContractInvocationStub.take(); | |||
return new ReturnIntValue(invocation); | |||
} | |||
/** | |||
* 解析合约方法调用的返回值; | |||
* <p> | |||
* 用法示例:<br> | |||
* <code> | |||
* ReturnLongValue retnHolder = decode(contract.issue(assetKey, amount)); | |||
* | |||
* PreparedTransaction prepTx = tx.prepare(); | |||
* prepTx.sign(userKey); | |||
* prepTx.commit() | |||
* | |||
* short retnValue = retnHolder.get(); //这是同步方法,会阻塞当前线程等待交易提交后返回结果; | |||
* </code> | |||
* | |||
* @param call | |||
* @return | |||
*/ | |||
public static ReturnShortValue decode(short call) { | |||
ContractInvocation invocation = ContractInvocationStub.take(); | |||
return new ReturnShortValue(invocation); | |||
} | |||
/** | |||
* 解析合约方法调用的返回值; | |||
* <p> | |||
* 用法示例:<br> | |||
* <code> | |||
* ReturnLongValue retnHolder = decode(contract.issue(assetKey, amount)); | |||
* | |||
* PreparedTransaction prepTx = tx.prepare(); | |||
* prepTx.sign(userKey); | |||
* prepTx.commit() | |||
* | |||
* byte retnValue = retnHolder.get(); //这是同步方法,会阻塞当前线程等待交易提交后返回结果; | |||
* </code> | |||
* | |||
* @param call | |||
* @return | |||
*/ | |||
public static ReturnByteValue decode(byte call) { | |||
ContractInvocation invocation = ContractInvocationStub.take(); | |||
return new ReturnByteValue(invocation); | |||
} | |||
/** | |||
* 解析合约方法调用的返回值; | |||
* <p> | |||
* 用法示例:<br> | |||
* <code> | |||
* ReturnLongValue retnHolder = decode(contract.issue(assetKey, amount)); | |||
* | |||
* PreparedTransaction prepTx = tx.prepare(); | |||
* prepTx.sign(userKey); | |||
* prepTx.commit() | |||
* | |||
* boolean retnValue = retnHolder.get(); //这是同步方法,会阻塞当前线程等待交易提交后返回结果; | |||
* </code> | |||
* | |||
* @param call | |||
* @return | |||
*/ | |||
public static ReturnBooleanValue decode(boolean call) { | |||
ContractInvocation invocation = ContractInvocationStub.take(); | |||
return new ReturnBooleanValue(invocation); | |||
} | |||
//----------------------- 内部类型 ----------------------- | |||
private static class ReturnValueBase { | |||
private ContractInvocation invocation; | |||
private ReturnValueBase(ContractInvocation invocation) { | |||
this.invocation = invocation; | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @return | |||
*/ | |||
private Object get() { | |||
try { | |||
return invocation.getReturnValue().get(); | |||
} catch (InterruptedException | ExecutionException e) { | |||
throw new IllegalStateException(e.getMessage(), e); | |||
} | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @param unit | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
private Object get(long timeout, TimeUnit unit) throws TimeoutException { | |||
try { | |||
return invocation.getReturnValue().get(timeout, unit); | |||
} catch (InterruptedException | ExecutionException e) { | |||
throw new IllegalStateException(e.getMessage(), e); | |||
} | |||
} | |||
} | |||
public static class ReturnValue<T> extends ReturnValueBase { | |||
private ReturnValue(ContractInvocation invocation) { | |||
super(invocation); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @return | |||
*/ | |||
@SuppressWarnings("unchecked") | |||
public T get() { | |||
return (T) super.get(); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public T get(long timeout) throws TimeoutException { | |||
return get(timeout, TimeUnit.MILLISECONDS); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @param unit | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
@SuppressWarnings("unchecked") | |||
public T get(long timeout, TimeUnit unit) throws TimeoutException { | |||
return (T) super.get(timeout, unit); | |||
} | |||
} | |||
public static class ReturnLongValue extends ReturnValueBase { | |||
private ReturnLongValue(ContractInvocation invocation) { | |||
super(invocation); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @return | |||
*/ | |||
public long get() { | |||
return (long) super.get(); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public long get(long timeout) throws TimeoutException { | |||
return get(timeout, TimeUnit.MILLISECONDS); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @param unit | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public long get(long timeout, TimeUnit unit) throws TimeoutException { | |||
return (long) super.get(timeout, unit); | |||
} | |||
} | |||
public static class ReturnIntValue extends ReturnValueBase { | |||
private ReturnIntValue(ContractInvocation invocation) { | |||
super(invocation); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @return | |||
*/ | |||
public int get() { | |||
return (int) super.get(); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public int get(long timeout) throws TimeoutException { | |||
return get(timeout, TimeUnit.MILLISECONDS); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @param unit | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public int get(long timeout, TimeUnit unit) throws TimeoutException { | |||
return (int) super.get(timeout, unit); | |||
} | |||
} | |||
public static class ReturnShortValue extends ReturnValueBase { | |||
private ReturnShortValue(ContractInvocation invocation) { | |||
super(invocation); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @return | |||
*/ | |||
public short get() { | |||
return (short) super.get(); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public short get(long timeout) throws TimeoutException { | |||
return get(timeout, TimeUnit.MILLISECONDS); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @param unit | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public short get(long timeout, TimeUnit unit) throws TimeoutException { | |||
return (short) super.get(timeout, unit); | |||
} | |||
} | |||
public static class ReturnByteValue extends ReturnValueBase { | |||
private ReturnByteValue(ContractInvocation invocation) { | |||
super(invocation); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @return | |||
*/ | |||
public byte get() { | |||
return (byte) super.get(); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public byte get(long timeout) throws TimeoutException { | |||
return get(timeout, TimeUnit.MILLISECONDS); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @param unit | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public byte get(long timeout, TimeUnit unit) throws TimeoutException { | |||
return (byte) super.get(timeout, unit); | |||
} | |||
} | |||
public static class ReturnBooleanValue extends ReturnValueBase { | |||
private ReturnBooleanValue(ContractInvocation invocation) { | |||
super(invocation); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @return | |||
*/ | |||
public boolean get() { | |||
return (boolean) super.get(); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public boolean get(long timeout) throws TimeoutException { | |||
return get(timeout, TimeUnit.MILLISECONDS); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @param unit | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public boolean get(long timeout, TimeUnit unit) throws TimeoutException { | |||
return (boolean) super.get(timeout, unit); | |||
} | |||
} | |||
} |
@@ -0,0 +1,43 @@ | |||
package com.jd.blockchain.transaction; | |||
import java.util.concurrent.TimeUnit; | |||
import java.util.concurrent.TimeoutException; | |||
public class IntValueHolder extends ValueHolderBase { | |||
IntValueHolder(ContractInvocation invocation) { | |||
super(invocation); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @return | |||
*/ | |||
public int get() { | |||
return (int) super.getValue(); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public int get(long timeout) throws TimeoutException { | |||
return get(timeout, TimeUnit.MILLISECONDS); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @param unit | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public int get(long timeout, TimeUnit unit) throws TimeoutException { | |||
return (int) super.getValue(timeout, unit); | |||
} | |||
} |
@@ -0,0 +1,43 @@ | |||
package com.jd.blockchain.transaction; | |||
import java.util.concurrent.TimeUnit; | |||
import java.util.concurrent.TimeoutException; | |||
public class LongValueHolder extends ValueHolderBase { | |||
LongValueHolder(ContractInvocation invocation) { | |||
super(invocation); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @return | |||
*/ | |||
public long get() { | |||
return (long) super.getValue(); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public long get(long timeout) throws TimeoutException { | |||
return get(timeout, TimeUnit.MILLISECONDS); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @param unit | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public long get(long timeout, TimeUnit unit) throws TimeoutException { | |||
return (long) super.getValue(timeout, unit); | |||
} | |||
} |
@@ -0,0 +1,43 @@ | |||
package com.jd.blockchain.transaction; | |||
import java.util.concurrent.TimeUnit; | |||
import java.util.concurrent.TimeoutException; | |||
public class ShortValueHolder extends ValueHolderBase { | |||
ShortValueHolder(ContractInvocation invocation) { | |||
super(invocation); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @return | |||
*/ | |||
public short get() { | |||
return (short) super.getValue(); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public short get(long timeout) throws TimeoutException { | |||
return get(timeout, TimeUnit.MILLISECONDS); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @param unit | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public short get(long timeout, TimeUnit unit) throws TimeoutException { | |||
return (short) super.getValue(timeout, unit); | |||
} | |||
} |
@@ -0,0 +1,45 @@ | |||
package com.jd.blockchain.transaction; | |||
import java.util.concurrent.TimeUnit; | |||
import java.util.concurrent.TimeoutException; | |||
public class ValueHolder<T> extends ValueHolderBase { | |||
ValueHolder(ContractInvocation invocation) { | |||
super(invocation); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @return | |||
*/ | |||
@SuppressWarnings("unchecked") | |||
public T get() { | |||
return (T) super.getValue(); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
public T get(long timeout) throws TimeoutException { | |||
return get(timeout, TimeUnit.MILLISECONDS); | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @param unit | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
@SuppressWarnings("unchecked") | |||
public T get(long timeout, TimeUnit unit) throws TimeoutException { | |||
return (T) super.getValue(timeout, unit); | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
package com.jd.blockchain.transaction; | |||
import java.util.concurrent.ExecutionException; | |||
import java.util.concurrent.TimeUnit; | |||
import java.util.concurrent.TimeoutException; | |||
class ValueHolderBase { | |||
private ContractInvocation invocation; | |||
protected ValueHolderBase(ContractInvocation invocation) { | |||
this.invocation = invocation; | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @return | |||
*/ | |||
protected Object getValue() { | |||
try { | |||
return invocation.getReturnValue().get(); | |||
} catch (InterruptedException | ExecutionException e) { | |||
throw new IllegalStateException(e.getMessage(), e); | |||
} | |||
} | |||
/** | |||
* 等待结果合约调用的结果返回; | |||
* | |||
* @param timeout | |||
* @param unit | |||
* @return | |||
* @throws TimeoutException | |||
*/ | |||
protected Object getValue(long timeout, TimeUnit unit) throws TimeoutException { | |||
try { | |||
return invocation.getReturnValue().get(timeout, unit); | |||
} catch (InterruptedException | ExecutionException e) { | |||
throw new IllegalStateException(e.getMessage(), e); | |||
} | |||
} | |||
} |
@@ -1,9 +1,8 @@ | |||
package com.jd.blockchain.sdk.samples; | |||
import static com.jd.blockchain.sdk.samples.SDKDemo_Constant.readChainCodes; | |||
import static com.jd.blockchain.transaction.ContractReturns.decode; | |||
import static com.jd.blockchain.transaction.ContractReturnValue.decode; | |||
import com.jd.blockchain.contract.EventResult; | |||
import com.jd.blockchain.contract.TransferContract; | |||
import com.jd.blockchain.ledger.BlockchainKeyGenerator; | |||
import com.jd.blockchain.ledger.BlockchainKeypair; | |||
@@ -11,9 +10,8 @@ import com.jd.blockchain.ledger.KVDataEntry; | |||
import com.jd.blockchain.ledger.PreparedTransaction; | |||
import com.jd.blockchain.ledger.TransactionResponse; | |||
import com.jd.blockchain.ledger.TransactionTemplate; | |||
import com.jd.blockchain.transaction.ContractEventExecutor; | |||
import com.jd.blockchain.transaction.ContractReturns.ReturnLongValue; | |||
import com.jd.blockchain.transaction.ContractReturns.ReturnValue; | |||
import com.jd.blockchain.transaction.LongValueHolder; | |||
import com.jd.blockchain.transaction.ValueHolder; | |||
import com.jd.blockchain.utils.Bytes; | |||
public class SDK_Contract_Demo extends SDK_Base_Demo { | |||
@@ -94,7 +92,7 @@ public class SDK_Contract_Demo extends SDK_Base_Demo { | |||
TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash); | |||
// 使用合约创建 | |||
TransferContract transferContract = txTpl.contract(contractAddress, TransferContract.class); | |||
ReturnValue<String> result = decode(transferContract.readAll(address, account)); | |||
ValueHolder<String> result = decode(transferContract.readAll(address, account)); | |||
commit(txTpl); | |||
return result.get(); | |||
} | |||
@@ -103,7 +101,7 @@ public class SDK_Contract_Demo extends SDK_Base_Demo { | |||
TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash); | |||
// 使用合约创建 | |||
TransferContract transferContract = txTpl.contract(contractAddress, TransferContract.class); | |||
ReturnLongValue result = decode(transferContract.read(address, account)); | |||
LongValueHolder result = decode(transferContract.read(address, account)); | |||
commit(txTpl); | |||
return result.get(); | |||
} | |||
@@ -124,7 +122,7 @@ public class SDK_Contract_Demo extends SDK_Base_Demo { | |||
TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash); | |||
// 使用合约创建 | |||
TransferContract transferContract = txTpl.contract(contractAddress, TransferContract.class); | |||
ReturnValue<String> result = decode(transferContract.transfer(address, from, to, money)); | |||
ValueHolder<String> result = decode(transferContract.transfer(address, from, to, money)); | |||
commit(txTpl); | |||
return result.get(); | |||
} | |||
@@ -144,7 +142,7 @@ public class SDK_Contract_Demo extends SDK_Base_Demo { | |||
if (useContract) { | |||
// 使用合约创建 | |||
TransferContract transferContract = txTpl.contract(contractAddress, TransferContract.class); | |||
ReturnValue<String> result = decode(transferContract.create(address, account, money)); | |||
ValueHolder<String> result = decode(transferContract.create(address, account, money)); | |||
commit(txTpl); | |||
return result.get(); | |||
} else { | |||
@@ -1,7 +1,7 @@ | |||
package test.com.jd.blockchain.sdk.test; | |||
import static com.jd.blockchain.sdk.samples.SDKDemo_Constant.readChainCodes; | |||
import static com.jd.blockchain.transaction.ContractReturns.decode; | |||
import static com.jd.blockchain.transaction.ContractReturnValue.decode; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
@@ -19,8 +19,8 @@ import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.sdk.client.GatewayServiceFactory; | |||
import com.jd.blockchain.sdk.samples.SDKDemo_Constant; | |||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | |||
import com.jd.blockchain.transaction.ContractReturns.ReturnLongValue; | |||
import com.jd.blockchain.transaction.ContractReturns.ReturnValue; | |||
import com.jd.blockchain.transaction.LongValueHolder; | |||
import com.jd.blockchain.transaction.ValueHolder; | |||
import com.jd.blockchain.utils.Bytes; | |||
public class SDKDemo_Contract_Test { | |||
@@ -108,7 +108,7 @@ public class SDKDemo_Contract_Test { | |||
TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash); | |||
// 使用合约创建 | |||
TransferContract transferContract = txTpl.contract(contractAddress, TransferContract.class); | |||
ReturnValue<String> result = decode(transferContract.readAll(address, account)); | |||
ValueHolder<String> result = decode(transferContract.readAll(address, account)); | |||
commit(txTpl); | |||
return result.get(); | |||
} | |||
@@ -117,7 +117,7 @@ public class SDKDemo_Contract_Test { | |||
TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash); | |||
// 使用合约创建 | |||
TransferContract transferContract = txTpl.contract(contractAddress, TransferContract.class); | |||
ReturnLongValue result = decode(transferContract.read(address, account)); | |||
LongValueHolder result = decode(transferContract.read(address, account)); | |||
commit(txTpl); | |||
return result.get(); | |||
} | |||
@@ -126,7 +126,7 @@ public class SDKDemo_Contract_Test { | |||
TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash); | |||
// 使用合约创建 | |||
TransferContract transferContract = txTpl.contract(contractAddress, TransferContract.class); | |||
ReturnValue<String> result = decode(transferContract.transfer(address, from, to, money)); | |||
ValueHolder<String> result = decode(transferContract.transfer(address, from, to, money)); | |||
commit(txTpl); | |||
return result.get(); | |||
} | |||
@@ -146,7 +146,7 @@ public class SDKDemo_Contract_Test { | |||
if (useContract) { | |||
// 使用合约创建 | |||
TransferContract transferContract = txTpl.contract(contractAddress, TransferContract.class); | |||
ReturnValue<String> result = decode(transferContract.create(address, account, money)); | |||
ValueHolder<String> result = decode(transferContract.create(address, account, money)); | |||
commit(txTpl); | |||
return result.get(); | |||
} else { | |||
@@ -8,6 +8,7 @@ | |||
*/ | |||
package test.com.jd.blockchain.intgr; | |||
import static com.jd.blockchain.transaction.ContractReturnValue.decode; | |||
import static org.junit.Assert.assertArrayEquals; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertNotNull; | |||
@@ -29,7 +30,6 @@ import org.springframework.core.io.ClassPathResource; | |||
import com.jd.blockchain.binaryproto.DataContractRegistry; | |||
import com.jd.blockchain.contract.ContractSerializeUtils; | |||
import com.jd.blockchain.contract.EventResult; | |||
import com.jd.blockchain.contract.ReadContract; | |||
import com.jd.blockchain.crypto.AddressEncoding; | |||
import com.jd.blockchain.crypto.AsymmetricKeypair; | |||
@@ -51,8 +51,7 @@ import com.jd.blockchain.sdk.BlockchainService; | |||
import com.jd.blockchain.storage.service.DbConnection; | |||
import com.jd.blockchain.storage.service.DbConnectionFactory; | |||
import com.jd.blockchain.tools.initializer.LedgerBindingConfig; | |||
import com.jd.blockchain.transaction.ContractEventExecutor; | |||
import static com.jd.blockchain.transaction.ContractReturns.*; | |||
import com.jd.blockchain.transaction.ValueHolder; | |||
import com.jd.blockchain.utils.Bytes; | |||
import com.jd.blockchain.utils.concurrent.ThreadInvoker; | |||
import com.jd.blockchain.utils.net.NetworkAddress; | |||
@@ -587,7 +586,7 @@ public class IntegrationBase { | |||
ReadContract readContract1 = txContract.contract(contractDeployKey.getAddress(), ReadContract.class); | |||
ReturnValue<String> result1 = decode(readContract1.read(newDataAccount.getAddress().toBase58(), key1)); | |||
ValueHolder<String> result1 = decode(readContract1.read(newDataAccount.getAddress().toBase58(), key1)); | |||
ReadContract readContract2 = txContract.contract(contractDeployKey.getAddress(), ReadContract.class); | |||
@@ -595,7 +594,7 @@ public class IntegrationBase { | |||
ReadContract readContract3 = txContract.contract(contractDeployKey.getAddress(), ReadContract.class); | |||
ReturnValue<Long> result3 = decode(readContract3.readVersion(newDataAccount.getAddress().toBase58(), key2)); | |||
ValueHolder<Long> result3 = decode(readContract3.readVersion(newDataAccount.getAddress().toBase58(), key2)); | |||
// 签名; | |||
PreparedTransaction contractPtx = txContract.prepare(); | |||