Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ public byte[] encodeConstructorFromBytes(String bin, byte[] params, String abi)
outputStream.write(params);
}
} else {
// deploy fir byte is 0, new byte[1] default is 0
outputStream.write(new byte[1]);

List<Type> deployParams = new ArrayList<>();
deployParams.add(new DynamicBytes(Hex.decode(bin)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public static byte[] encodeParameters(List<Type> parameters, byte[] methodID) {
try {
ScaleCodecWriter writer = new ScaleCodecWriter(result);
if (methodID != null) {
byte[] wasmFlag = new byte[1];
wasmFlag[0] = 1;
result.write(wasmFlag);
result.write(methodID);
}
for (Type parameter : parameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

@TarsStruct
public class Transaction {
public static final int LIQUID_SCALE_CODEC = 0x2;
public static final int LIQUID_CREATE = 0x8;

@TarsStructProperty(order = 1, isRequire = false)
public TransactionData data = null;
Expand All @@ -26,55 +28,87 @@ public class Transaction {
@TarsStructProperty(order = 4, isRequire = false)
public long importTime = 0L;

@TarsStructProperty(order = 5, isRequire = false)
public int attribute = 0;

@TarsStructProperty(order = 6, isRequire = false)
public String source = "";

public TransactionData getData() {
return this.data;
return data;
}

public void setData(TransactionData data) {
this.data = data;
}

public byte[] getDataHash() {
return this.dataHash;
return dataHash;
}

public void setDataHash(byte[] dataHash) {
this.dataHash = dataHash;
}

public byte[] getSignature() {
return this.signature;
return signature;
}

public void setSignature(byte[] signature) {
this.signature = signature;
}

public long getImportTime() {
return this.importTime;
return importTime;
}

public void setImportTime(long importTime) {
this.importTime = importTime;
}

public int getAttribute() {
return attribute;
}

public void setAttribute(int attribute) {
this.attribute = attribute;
}

public String getSource() {
return source;
}

public void setSource(String source) {
this.source = source;
}

public Transaction() {}

public Transaction(TransactionData data, byte[] dataHash, byte[] signature, long importTime) {
public Transaction(
TransactionData data,
byte[] dataHash,
byte[] signature,
long importTime,
int attribute,
String source) {
this.data = data;
this.dataHash = dataHash;
this.signature = signature;
this.importTime = importTime;
this.attribute = attribute;
this.source = source;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + TarsUtil.hashCode(this.data);
result = prime * result + TarsUtil.hashCode(this.dataHash);
result = prime * result + TarsUtil.hashCode(this.signature);
result = prime * result + TarsUtil.hashCode(this.importTime);
result = prime * result + TarsUtil.hashCode(data);
result = prime * result + TarsUtil.hashCode(dataHash);
result = prime * result + TarsUtil.hashCode(signature);
result = prime * result + TarsUtil.hashCode(importTime);
result = prime * result + TarsUtil.hashCode(attribute);
result = prime * result + TarsUtil.hashCode(source);
return result;
}

Expand All @@ -90,10 +124,12 @@ public boolean equals(Object obj) {
return false;
}
Transaction other = (Transaction) obj;
return (TarsUtil.equals(this.data, other.data)
&& TarsUtil.equals(this.dataHash, other.dataHash)
&& TarsUtil.equals(this.signature, other.signature)
&& TarsUtil.equals(this.importTime, other.importTime));
return (TarsUtil.equals(data, other.data)
&& TarsUtil.equals(dataHash, other.dataHash)
&& TarsUtil.equals(signature, other.signature)
&& TarsUtil.equals(importTime, other.importTime)
&& TarsUtil.equals(attribute, other.attribute)
&& TarsUtil.equals(source, other.source));
}

@Override
Expand Down Expand Up @@ -122,21 +158,35 @@ public String toString() {
sb.append(", ");
sb.append("importTime:");
sb.append(this.importTime);
sb.append(", ");
sb.append("attribute:");
sb.append(this.attribute);
sb.append(", ");
sb.append("source:");
if (this.source == null) {
sb.append("null");
} else {
sb.append(this.source);
}
sb.append(")");
return sb.toString();
}

public void writeTo(TarsOutputStream _os) {
if (null != this.data) {
_os.write(this.data, 1);
if (null != data) {
_os.write(data, 1);
}
if (null != dataHash) {
_os.write(dataHash, 2);
}
if (null != this.dataHash) {
_os.write(this.dataHash, 2);
if (null != signature) {
_os.write(signature, 3);
}
if (null != this.signature) {
_os.write(this.signature, 3);
_os.write(importTime, 4);
_os.write(attribute, 5);
if (null != source) {
_os.write(source, 6);
}
_os.write(this.importTime, 4);
}

static TransactionData cache_data;
Expand All @@ -149,22 +199,24 @@ public void writeTo(TarsOutputStream _os) {

static {
cache_dataHash = new byte[1];
byte var_12 = (byte) 0;
cache_dataHash[0] = var_12;
byte var_2 = (byte) 0;
cache_dataHash[0] = var_2;
}

static byte[] cache_signature;

static {
cache_signature = new byte[1];
byte var_13 = (byte) 0;
cache_signature[0] = var_13;
byte var_3 = (byte) 0;
cache_signature[0] = var_3;
}

public void readFrom(TarsInputStream _is) {
this.data = (TransactionData) _is.read(cache_data, 1, false);
this.dataHash = (byte[]) _is.read(cache_dataHash, 2, false);
this.signature = (byte[]) _is.read(cache_signature, 3, false);
this.importTime = _is.read(this.importTime, 4, false);
this.importTime = _is.read(importTime, 4, false);
this.attribute = _is.read(attribute, 5, false);
this.source = _is.readString(6, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
*/
package org.fisco.bcos.sdk.contract;

import static org.fisco.bcos.sdk.client.protocol.model.tars.Transaction.LIQUID_CREATE;
import static org.fisco.bcos.sdk.client.protocol.model.tars.Transaction.LIQUID_SCALE_CODEC;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
Expand Down Expand Up @@ -289,8 +292,15 @@ protected List<Type> executeCallWithMultipleValueReturn(Function function)

protected void asyncExecuteTransaction(
byte[] data, String funName, TransactionCallback callback) {
int txAttribute = 0;
if (client.isWASM()) {
txAttribute = LIQUID_SCALE_CODEC;
if (funName == FUNC_DEPLOY) {
txAttribute |= LIQUID_CREATE;
}
}
this.transactionProcessor.sendTransactionAsync(
this.contractAddress, data, this.credential, callback);
this.contractAddress, data, this.credential, txAttribute, callback);
}

protected void asyncExecuteTransaction(Function function, TransactionCallback callback) {
Expand All @@ -303,8 +313,15 @@ protected TransactionReceipt executeTransaction(Function function) {
}

protected TransactionReceipt executeTransaction(byte[] data, String functionName) {
int txAttribute = 0;
if (client.isWASM()) {
txAttribute = LIQUID_SCALE_CODEC;
if (functionName == FUNC_DEPLOY) {
txAttribute |= LIQUID_CREATE;
}
}
return this.transactionProcessor.sendTransactionAndGetReceipt(
this.contractAddress, data, this.credential);
this.contractAddress, data, this.credential, txAttribute);
}

/** Adds a log field to {@link EventValues}. */
Expand All @@ -331,12 +348,20 @@ public TransactionReceipt.Logs getLog() {
}

protected String createSignedTransaction(Function function) {
int txAttribute = 0;
if (client.isWASM()) {
txAttribute = LIQUID_SCALE_CODEC;
if (function.getName() == FUNC_DEPLOY) {
txAttribute |= LIQUID_CREATE;
}
}
return this.createSignedTransaction(
this.contractAddress, this.functionEncoder.encode(function));
this.contractAddress, this.functionEncoder.encode(function), txAttribute);
}

protected String createSignedTransaction(String to, byte[] data) {
return this.transactionProcessor.createSignedTransaction(to, data, this.credential);
protected String createSignedTransaction(String to, byte[] data, int txAttribute) {
return this.transactionProcessor.createSignedTransaction(
to, data, this.credential, txAttribute);
}

public static EventValues staticExtractEventParameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public static String createSignedTransaction(
String to,
String functionName,
List<Object> params,
boolean isWasm)
boolean isWasm,
int txAttribute)
throws ABICodecException {
ABICodec abiCodec = new ABICodec(cryptoSuite, isWasm);
byte[] data = abiCodec.encodeMethod(abi, functionName, params);
Expand All @@ -73,7 +74,8 @@ public static String createSignedTransaction(
0, chainId, groupId, blockLimit.intValue(), randomId.toString(), to, data);

TransactionEncoderService transactionEncoder = new TransactionEncoderService(cryptoSuite);
return transactionEncoder.encodeAndSign(rawTransaction, cryptoSuite.getCryptoKeyPair());
return transactionEncoder.encodeAndSign(
rawTransaction, cryptoSuite.getCryptoKeyPair(), txAttribute);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public interface TransactionEncoderInterface {
* @param cryptoKeyPair keypair
* @return encoded & signed transaction byte array
*/
byte[] encodeAndSignBytes(TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair);
byte[] encodeAndSignBytes(
TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair, int attribute);

/**
* Tars encode and sign based on TransactionData
Expand All @@ -48,7 +49,8 @@ public interface TransactionEncoderInterface {
* @param cryptoKeyPair keypair
* @return encoded & signed transaction hexed String
*/
String encodeAndSign(TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair);
String encodeAndSign(
TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair, int attribute);

/**
* Tars encode and hash based on TransactionData
Expand All @@ -67,7 +69,7 @@ public interface TransactionEncoderInterface {
* @return
*/
byte[] encodeToTransactionBytes(
TransactionData rawTransaction, byte[] hash, SignatureResult result);
TransactionData rawTransaction, byte[] hash, SignatureResult result, int attribute);

/**
* Tars encode rawTransaction to Transaction bytes
Expand All @@ -76,5 +78,6 @@ byte[] encodeToTransactionBytes(
* @param result
* @return
*/
byte[] encodeToTransactionBytes(TransactionData rawTransaction, SignatureResult result);
byte[] encodeToTransactionBytes(
TransactionData rawTransaction, SignatureResult result, int attribute);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ public byte[] encode(TransactionData rawTransaction) {
}

@Override
public String encodeAndSign(TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair) {
public String encodeAndSign(
TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair, int attribute) {
return Base64.getEncoder()
.encodeToString(this.encodeAndSignBytes(rawTransaction, cryptoKeyPair));
.encodeToString(this.encodeAndSignBytes(rawTransaction, cryptoKeyPair, attribute));
}

@Override
Expand All @@ -73,25 +74,28 @@ public byte[] encodeAndHashBytes(TransactionData rawTransaction) {
}

@Override
public byte[] encodeAndSignBytes(TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair) {
public byte[] encodeAndSignBytes(
TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair, int attribute) {
byte[] hash = this.encodeAndHashBytes(rawTransaction);
SignatureResult result = this.transactionSignerService.sign(hash, cryptoKeyPair);
return this.encodeToTransactionBytes(rawTransaction, hash, result);
return this.encodeToTransactionBytes(rawTransaction, hash, result, attribute);
}

@Override
public byte[] encodeToTransactionBytes(
TransactionData rawTransaction, byte[] hash, SignatureResult result) {
Transaction transaction = new Transaction(rawTransaction, hash, result.encode(), 0);
TransactionData rawTransaction, byte[] hash, SignatureResult result, int attribute) {
Transaction transaction =
new Transaction(rawTransaction, hash, result.encode(), 0, attribute, null);
TarsOutputStream tarsOutputStream = new TarsOutputStream();
transaction.writeTo(tarsOutputStream);
return tarsOutputStream.toByteArray();
}

@Override
public byte[] encodeToTransactionBytes(TransactionData rawTransaction, SignatureResult result) {
public byte[] encodeToTransactionBytes(
TransactionData rawTransaction, SignatureResult result, int attribute) {
byte[] hash = this.cryptoSuite.hash(encode(rawTransaction));
return encodeToTransactionBytes(rawTransaction, hash, result);
return encodeToTransactionBytes(rawTransaction, hash, result, attribute);
}

/** @return the signature */
Expand Down
Loading