Skip to content

Commit f149aaf

Browse files
remove the 1 magic byte of liquid deploy and call (#418)
* remove the 1 magic byte of liquid deploy and call * add LIQUID_SCALE_CODEC Co-authored-by: cyjseagull <1547158861@qq.com>
1 parent 51bb448 commit f149aaf

File tree

15 files changed

+227
-78
lines changed

15 files changed

+227
-78
lines changed

sdk-codec/src/main/java/org/fisco/bcos/sdk/codec/ABICodec.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,6 @@ public byte[] encodeConstructorFromBytes(String bin, byte[] params, String abi)
318318
outputStream.write(params);
319319
}
320320
} else {
321-
// deploy fir byte is 0, new byte[1] default is 0
322-
outputStream.write(new byte[1]);
323321

324322
List<Type> deployParams = new ArrayList<>();
325323
deployParams.add(new DynamicBytes(Hex.decode(bin)));

sdk-codec/src/main/java/org/fisco/bcos/sdk/codec/scale/FunctionEncoder.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ public static byte[] encodeParameters(List<Type> parameters, byte[] methodID) {
3232
try {
3333
ScaleCodecWriter writer = new ScaleCodecWriter(result);
3434
if (methodID != null) {
35-
byte[] wasmFlag = new byte[1];
36-
wasmFlag[0] = 1;
37-
result.write(wasmFlag);
3835
result.write(methodID);
3936
}
4037
for (Type parameter : parameters) {

sdk-service/src/main/java/org/fisco/bcos/sdk/client/protocol/model/tars/Transaction.java

Lines changed: 77 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
@TarsStruct
1515
public class Transaction {
16+
public static final int LIQUID_SCALE_CODEC = 0x2;
17+
public static final int LIQUID_CREATE = 0x8;
1618

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

31+
@TarsStructProperty(order = 5, isRequire = false)
32+
public int attribute = 0;
33+
34+
@TarsStructProperty(order = 6, isRequire = false)
35+
public String source = "";
36+
2937
public TransactionData getData() {
30-
return this.data;
38+
return data;
3139
}
3240

3341
public void setData(TransactionData data) {
3442
this.data = data;
3543
}
3644

3745
public byte[] getDataHash() {
38-
return this.dataHash;
46+
return dataHash;
3947
}
4048

4149
public void setDataHash(byte[] dataHash) {
4250
this.dataHash = dataHash;
4351
}
4452

4553
public byte[] getSignature() {
46-
return this.signature;
54+
return signature;
4755
}
4856

4957
public void setSignature(byte[] signature) {
5058
this.signature = signature;
5159
}
5260

5361
public long getImportTime() {
54-
return this.importTime;
62+
return importTime;
5563
}
5664

5765
public void setImportTime(long importTime) {
5866
this.importTime = importTime;
5967
}
6068

69+
public int getAttribute() {
70+
return attribute;
71+
}
72+
73+
public void setAttribute(int attribute) {
74+
this.attribute = attribute;
75+
}
76+
77+
public String getSource() {
78+
return source;
79+
}
80+
81+
public void setSource(String source) {
82+
this.source = source;
83+
}
84+
6185
public Transaction() {}
6286

63-
public Transaction(TransactionData data, byte[] dataHash, byte[] signature, long importTime) {
87+
public Transaction(
88+
TransactionData data,
89+
byte[] dataHash,
90+
byte[] signature,
91+
long importTime,
92+
int attribute,
93+
String source) {
6494
this.data = data;
6595
this.dataHash = dataHash;
6696
this.signature = signature;
6797
this.importTime = importTime;
98+
this.attribute = attribute;
99+
this.source = source;
68100
}
69101

70102
@Override
71103
public int hashCode() {
72104
final int prime = 31;
73105
int result = 1;
74-
result = prime * result + TarsUtil.hashCode(this.data);
75-
result = prime * result + TarsUtil.hashCode(this.dataHash);
76-
result = prime * result + TarsUtil.hashCode(this.signature);
77-
result = prime * result + TarsUtil.hashCode(this.importTime);
106+
result = prime * result + TarsUtil.hashCode(data);
107+
result = prime * result + TarsUtil.hashCode(dataHash);
108+
result = prime * result + TarsUtil.hashCode(signature);
109+
result = prime * result + TarsUtil.hashCode(importTime);
110+
result = prime * result + TarsUtil.hashCode(attribute);
111+
result = prime * result + TarsUtil.hashCode(source);
78112
return result;
79113
}
80114

@@ -90,10 +124,12 @@ public boolean equals(Object obj) {
90124
return false;
91125
}
92126
Transaction other = (Transaction) obj;
93-
return (TarsUtil.equals(this.data, other.data)
94-
&& TarsUtil.equals(this.dataHash, other.dataHash)
95-
&& TarsUtil.equals(this.signature, other.signature)
96-
&& TarsUtil.equals(this.importTime, other.importTime));
127+
return (TarsUtil.equals(data, other.data)
128+
&& TarsUtil.equals(dataHash, other.dataHash)
129+
&& TarsUtil.equals(signature, other.signature)
130+
&& TarsUtil.equals(importTime, other.importTime)
131+
&& TarsUtil.equals(attribute, other.attribute)
132+
&& TarsUtil.equals(source, other.source));
97133
}
98134

99135
@Override
@@ -122,21 +158,35 @@ public String toString() {
122158
sb.append(", ");
123159
sb.append("importTime:");
124160
sb.append(this.importTime);
161+
sb.append(", ");
162+
sb.append("attribute:");
163+
sb.append(this.attribute);
164+
sb.append(", ");
165+
sb.append("source:");
166+
if (this.source == null) {
167+
sb.append("null");
168+
} else {
169+
sb.append(this.source);
170+
}
125171
sb.append(")");
126172
return sb.toString();
127173
}
128174

129175
public void writeTo(TarsOutputStream _os) {
130-
if (null != this.data) {
131-
_os.write(this.data, 1);
176+
if (null != data) {
177+
_os.write(data, 1);
178+
}
179+
if (null != dataHash) {
180+
_os.write(dataHash, 2);
132181
}
133-
if (null != this.dataHash) {
134-
_os.write(this.dataHash, 2);
182+
if (null != signature) {
183+
_os.write(signature, 3);
135184
}
136-
if (null != this.signature) {
137-
_os.write(this.signature, 3);
185+
_os.write(importTime, 4);
186+
_os.write(attribute, 5);
187+
if (null != source) {
188+
_os.write(source, 6);
138189
}
139-
_os.write(this.importTime, 4);
140190
}
141191

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

150200
static {
151201
cache_dataHash = new byte[1];
152-
byte var_12 = (byte) 0;
153-
cache_dataHash[0] = var_12;
202+
byte var_2 = (byte) 0;
203+
cache_dataHash[0] = var_2;
154204
}
155205

156206
static byte[] cache_signature;
157207

158208
static {
159209
cache_signature = new byte[1];
160-
byte var_13 = (byte) 0;
161-
cache_signature[0] = var_13;
210+
byte var_3 = (byte) 0;
211+
cache_signature[0] = var_3;
162212
}
163213

164214
public void readFrom(TarsInputStream _is) {
165215
this.data = (TransactionData) _is.read(cache_data, 1, false);
166216
this.dataHash = (byte[]) _is.read(cache_dataHash, 2, false);
167217
this.signature = (byte[]) _is.read(cache_signature, 3, false);
168-
this.importTime = _is.read(this.importTime, 4, false);
218+
this.importTime = _is.read(importTime, 4, false);
219+
this.attribute = _is.read(attribute, 5, false);
220+
this.source = _is.readString(6, false);
169221
}
170222
}

sdk-transaction/src/main/java/org/fisco/bcos/sdk/contract/Contract.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
*/
1515
package org.fisco.bcos.sdk.contract;
1616

17+
import static org.fisco.bcos.sdk.client.protocol.model.tars.Transaction.LIQUID_CREATE;
18+
import static org.fisco.bcos.sdk.client.protocol.model.tars.Transaction.LIQUID_SCALE_CODEC;
19+
1720
import java.lang.reflect.Constructor;
1821
import java.lang.reflect.InvocationTargetException;
1922
import java.util.*;
@@ -289,8 +292,15 @@ protected List<Type> executeCallWithMultipleValueReturn(Function function)
289292

290293
protected void asyncExecuteTransaction(
291294
byte[] data, String funName, TransactionCallback callback) {
295+
int txAttribute = 0;
296+
if (client.isWASM()) {
297+
txAttribute = LIQUID_SCALE_CODEC;
298+
if (funName == FUNC_DEPLOY) {
299+
txAttribute |= LIQUID_CREATE;
300+
}
301+
}
292302
this.transactionProcessor.sendTransactionAsync(
293-
this.contractAddress, data, this.credential, callback);
303+
this.contractAddress, data, this.credential, txAttribute, callback);
294304
}
295305

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

305315
protected TransactionReceipt executeTransaction(byte[] data, String functionName) {
316+
int txAttribute = 0;
317+
if (client.isWASM()) {
318+
txAttribute = LIQUID_SCALE_CODEC;
319+
if (functionName == FUNC_DEPLOY) {
320+
txAttribute |= LIQUID_CREATE;
321+
}
322+
}
306323
return this.transactionProcessor.sendTransactionAndGetReceipt(
307-
this.contractAddress, data, this.credential);
324+
this.contractAddress, data, this.credential, txAttribute);
308325
}
309326

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

333350
protected String createSignedTransaction(Function function) {
351+
int txAttribute = 0;
352+
if (client.isWASM()) {
353+
txAttribute = LIQUID_SCALE_CODEC;
354+
if (function.getName() == FUNC_DEPLOY) {
355+
txAttribute |= LIQUID_CREATE;
356+
}
357+
}
334358
return this.createSignedTransaction(
335-
this.contractAddress, this.functionEncoder.encode(function));
359+
this.contractAddress, this.functionEncoder.encode(function), txAttribute);
336360
}
337361

338-
protected String createSignedTransaction(String to, byte[] data) {
339-
return this.transactionProcessor.createSignedTransaction(to, data, this.credential);
362+
protected String createSignedTransaction(String to, byte[] data, int txAttribute) {
363+
return this.transactionProcessor.createSignedTransaction(
364+
to, data, this.credential, txAttribute);
340365
}
341366

342367
public static EventValues staticExtractEventParameters(

sdk-transaction/src/main/java/org/fisco/bcos/sdk/transaction/builder/TransactionBuilderService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public static String createSignedTransaction(
6262
String to,
6363
String functionName,
6464
List<Object> params,
65-
boolean isWasm)
65+
boolean isWasm,
66+
int txAttribute)
6667
throws ABICodecException {
6768
ABICodec abiCodec = new ABICodec(cryptoSuite, isWasm);
6869
byte[] data = abiCodec.encodeMethod(abi, functionName, params);
@@ -73,7 +74,8 @@ public static String createSignedTransaction(
7374
0, chainId, groupId, blockLimit.intValue(), randomId.toString(), to, data);
7475

7576
TransactionEncoderService transactionEncoder = new TransactionEncoderService(cryptoSuite);
76-
return transactionEncoder.encodeAndSign(rawTransaction, cryptoSuite.getCryptoKeyPair());
77+
return transactionEncoder.encodeAndSign(
78+
rawTransaction, cryptoSuite.getCryptoKeyPair(), txAttribute);
7779
}
7880

7981
@Override

sdk-transaction/src/main/java/org/fisco/bcos/sdk/transaction/codec/encode/TransactionEncoderInterface.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public interface TransactionEncoderInterface {
3939
* @param cryptoKeyPair keypair
4040
* @return encoded & signed transaction byte array
4141
*/
42-
byte[] encodeAndSignBytes(TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair);
42+
byte[] encodeAndSignBytes(
43+
TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair, int attribute);
4344

4445
/**
4546
* Tars encode and sign based on TransactionData
@@ -48,7 +49,8 @@ public interface TransactionEncoderInterface {
4849
* @param cryptoKeyPair keypair
4950
* @return encoded & signed transaction hexed String
5051
*/
51-
String encodeAndSign(TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair);
52+
String encodeAndSign(
53+
TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair, int attribute);
5254

5355
/**
5456
* Tars encode and hash based on TransactionData
@@ -67,7 +69,7 @@ public interface TransactionEncoderInterface {
6769
* @return
6870
*/
6971
byte[] encodeToTransactionBytes(
70-
TransactionData rawTransaction, byte[] hash, SignatureResult result);
72+
TransactionData rawTransaction, byte[] hash, SignatureResult result, int attribute);
7173

7274
/**
7375
* Tars encode rawTransaction to Transaction bytes
@@ -76,5 +78,6 @@ byte[] encodeToTransactionBytes(
7678
* @param result
7779
* @return
7880
*/
79-
byte[] encodeToTransactionBytes(TransactionData rawTransaction, SignatureResult result);
81+
byte[] encodeToTransactionBytes(
82+
TransactionData rawTransaction, SignatureResult result, int attribute);
8083
}

sdk-transaction/src/main/java/org/fisco/bcos/sdk/transaction/codec/encode/TransactionEncoderService.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ public byte[] encode(TransactionData rawTransaction) {
6060
}
6161

6262
@Override
63-
public String encodeAndSign(TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair) {
63+
public String encodeAndSign(
64+
TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair, int attribute) {
6465
return Base64.getEncoder()
65-
.encodeToString(this.encodeAndSignBytes(rawTransaction, cryptoKeyPair));
66+
.encodeToString(this.encodeAndSignBytes(rawTransaction, cryptoKeyPair, attribute));
6667
}
6768

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

7576
@Override
76-
public byte[] encodeAndSignBytes(TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair) {
77+
public byte[] encodeAndSignBytes(
78+
TransactionData rawTransaction, CryptoKeyPair cryptoKeyPair, int attribute) {
7779
byte[] hash = this.encodeAndHashBytes(rawTransaction);
7880
SignatureResult result = this.transactionSignerService.sign(hash, cryptoKeyPair);
79-
return this.encodeToTransactionBytes(rawTransaction, hash, result);
81+
return this.encodeToTransactionBytes(rawTransaction, hash, result, attribute);
8082
}
8183

8284
@Override
8385
public byte[] encodeToTransactionBytes(
84-
TransactionData rawTransaction, byte[] hash, SignatureResult result) {
85-
Transaction transaction = new Transaction(rawTransaction, hash, result.encode(), 0);
86+
TransactionData rawTransaction, byte[] hash, SignatureResult result, int attribute) {
87+
Transaction transaction =
88+
new Transaction(rawTransaction, hash, result.encode(), 0, attribute, null);
8689
TarsOutputStream tarsOutputStream = new TarsOutputStream();
8790
transaction.writeTo(tarsOutputStream);
8891
return tarsOutputStream.toByteArray();
8992
}
9093

9194
@Override
92-
public byte[] encodeToTransactionBytes(TransactionData rawTransaction, SignatureResult result) {
95+
public byte[] encodeToTransactionBytes(
96+
TransactionData rawTransaction, SignatureResult result, int attribute) {
9397
byte[] hash = this.cryptoSuite.hash(encode(rawTransaction));
94-
return encodeToTransactionBytes(rawTransaction, hash, result);
98+
return encodeToTransactionBytes(rawTransaction, hash, result, attribute);
9599
}
96100

97101
/** @return the signature */

0 commit comments

Comments
 (0)