Skip to content

Commit

Permalink
add support for soroban prev 8
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Apr 8, 2023
1 parent e156c81 commit e6ceaf6
Show file tree
Hide file tree
Showing 19 changed files with 1,112 additions and 944 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [1.5.3] - 08.Apr.2023.
- add support for soroban prev 8
- improve soroban tests & docs
- add missing proof_of_liveness kyc field

## [1.5.2] - 03.Mar.2023.
- add support for soroban prev 7
- add support for soroban auth next
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The Soneso open source Stellar SDK for Flutter is build with Dart and provides A
1. Add the dependency to your pubspec.yaml file:
```
dependencies:
stellar_flutter_sdk: ^1.5.2
stellar_flutter_sdk: ^1.5.3
```
2. Install it (command line or IDE):
```
Expand Down
38 changes: 15 additions & 23 deletions lib/src/invoke_host_function_operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ abstract class InvokeHostFunctionOperation extends Operation {
op.function.createContractArgs!.contractID.discriminant ==
XdrContractIDType.CONTRACT_ID_FROM_SOURCE_ACCOUNT) {
if (op.function.createContractArgs!.source.discriminant ==
XdrSCContractCodeType.SCCONTRACT_CODE_WASM_REF) {
XdrSCContractExecutableType.SCCONTRACT_EXECUTABLE_WASM_REF) {
// use builder of create contract op
return CreateContractOp.builder(op);
} else if (op.function.createContractArgs!.source.discriminant ==
XdrSCContractCodeType.SCCONTRACT_CODE_TOKEN) {
XdrSCContractExecutableType.SCCONTRACT_EXECUTABLE_TOKEN) {
// use builder of deploy stellar asset contract with account op
return DeploySACWithSourceAccountOp.builder(op);
}
Expand Down Expand Up @@ -254,10 +254,7 @@ class InvokeContractOp extends InvokeHostFunctionOperation {
List<XdrSCVal> invokeArgsList = List<XdrSCVal>.empty(growable: true);

// contract id
XdrSCVal contractIDScVal = XdrSCVal(XdrSCValType.SCV_OBJECT);
XdrSCObject contractIDSCObject = XdrSCObject(XdrSCObjectType.SCO_BYTES);
contractIDSCObject.bin = XdrDataValue(Util.hexToBytes(this._contractID));
contractIDScVal.obj = contractIDSCObject;
XdrSCVal contractIDScVal = XdrSCVal.forBytes(Util.hexToBytes(this._contractID));
invokeArgsList.add(contractIDScVal);

// function name
Expand Down Expand Up @@ -292,19 +289,14 @@ class InvokeContractOp extends InvokeHostFunctionOperation {

List<XdrSCVal> invokeArgsList = xdrHostFunction.invokeArgs!;
if (invokeArgsList.length < 2 ||
invokeArgsList.elementAt(0).discriminant != XdrSCValType.SCV_OBJECT ||
invokeArgsList.elementAt(0).obj == null ||
invokeArgsList.elementAt(0).discriminant != XdrSCValType.SCV_BYTES ||
invokeArgsList.elementAt(0).bytes == null ||
invokeArgsList.elementAt(1).discriminant != XdrSCValType.SCV_SYMBOL ||
invokeArgsList.elementAt(1).sym == null) {
throw new Exception("invalid argument");
}

XdrSCObject contractIDSCObject = invokeArgsList.elementAt(0).obj!;
if (contractIDSCObject.discriminant != XdrSCObjectType.SCO_BYTES ||
contractIDSCObject.bin == null) {
throw new Exception("invalid argument");
}
String contractID = Util.bytesToHex(contractIDSCObject.bin!.dataValue);
String contractID = Util.bytesToHex(invokeArgsList.elementAt(0).bytes!.dataValue);
String functionName = invokeArgsList.elementAt(1).sym!;

List<XdrSCVal>? funcArgs;
Expand Down Expand Up @@ -387,8 +379,8 @@ class CreateContractOp extends InvokeHostFunctionOperation {
XdrContractID(XdrContractIDType.CONTRACT_ID_FROM_SOURCE_ACCOUNT);
contractId.salt = this._salt;

XdrSCContractCode code =
XdrSCContractCode(XdrSCContractCodeType.SCCONTRACT_CODE_WASM_REF);
XdrSCContractExecutable code =
XdrSCContractExecutable(XdrSCContractExecutableType.SCCONTRACT_EXECUTABLE_WASM_REF);
code.wasmId = XdrHash(Util.hexToBytes(wasmId));

xdrHostFunction.createContractArgs =
Expand All @@ -409,7 +401,7 @@ class CreateContractOp extends InvokeHostFunctionOperation {
xdrHostFunction.createContractArgs!.contractID.discriminant !=
XdrContractIDType.CONTRACT_ID_FROM_SOURCE_ACCOUNT ||
xdrHostFunction.createContractArgs!.source.discriminant !=
XdrSCContractCodeType.SCCONTRACT_CODE_WASM_REF ||
XdrSCContractExecutableType.SCCONTRACT_EXECUTABLE_WASM_REF ||
xdrHostFunction.createContractArgs!.source.wasmId == null) {
throw new Exception("invalid argument");
}
Expand Down Expand Up @@ -450,8 +442,8 @@ class DeploySACWithSourceAccountOp extends InvokeHostFunctionOperation {
XdrContractID(XdrContractIDType.CONTRACT_ID_FROM_SOURCE_ACCOUNT);
contractId.salt = this._salt;

XdrSCContractCode code =
XdrSCContractCode(XdrSCContractCodeType.SCCONTRACT_CODE_TOKEN);
XdrSCContractExecutable code =
XdrSCContractExecutable(XdrSCContractExecutableType.SCCONTRACT_EXECUTABLE_TOKEN);

xdrHostFunction.createContractArgs =
XdrCreateContractArgs(contractId, code);
Expand All @@ -471,7 +463,7 @@ class DeploySACWithSourceAccountOp extends InvokeHostFunctionOperation {
xdrHostFunction.createContractArgs!.contractID.discriminant !=
XdrContractIDType.CONTRACT_ID_FROM_SOURCE_ACCOUNT ||
xdrHostFunction.createContractArgs!.source.discriminant !=
XdrSCContractCodeType.SCCONTRACT_CODE_TOKEN) {
XdrSCContractExecutableType.SCCONTRACT_EXECUTABLE_TOKEN) {
throw new Exception("invalid argument");
}

Expand All @@ -498,8 +490,8 @@ class DeploySACWithAssetOp extends InvokeHostFunctionOperation {
XdrContractID(XdrContractIDType.CONTRACT_ID_FROM_ASSET);
contractId.asset = this._asset.toXdr();

XdrSCContractCode code =
XdrSCContractCode(XdrSCContractCodeType.SCCONTRACT_CODE_TOKEN);
XdrSCContractExecutable code =
XdrSCContractExecutable(XdrSCContractExecutableType.SCCONTRACT_EXECUTABLE_TOKEN);

xdrHostFunction.createContractArgs =
XdrCreateContractArgs(contractId, code);
Expand All @@ -520,7 +512,7 @@ class DeploySACWithAssetOp extends InvokeHostFunctionOperation {
XdrContractIDType.CONTRACT_ID_FROM_ASSET ||
xdrHostFunction.createContractArgs!.contractID.asset == null ||
xdrHostFunction.createContractArgs!.source.discriminant !=
XdrSCContractCodeType.SCCONTRACT_CODE_TOKEN) {
XdrSCContractExecutableType.SCCONTRACT_EXECUTABLE_TOKEN) {
throw new Exception("invalid argument");
}

Expand Down
16 changes: 9 additions & 7 deletions lib/src/sep/0011/txrep.dart
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,14 @@ class TxRep {
String opPrefix = prefix + 'liquidityPoolWithdrawOp.';
return _getLiquidityPoolWithdrawOp(sourceAccountId, opPrefix, map);
}
if (opType == 'INVOKE_HOST_FUNCTION') {
/*if (opType == 'INVOKE_HOST_FUNCTION') {
String opPrefix = prefix + 'invokeHostFunctionOp.';
return _getInvokeHostFunctionOp(sourceAccountId, opPrefix, map);
}
}*/
throw Exception('invalid or unsupported [$prefix].type - $opType');
}

/*
static InvokeHostFunctionOperation _getInvokeHostFunctionOp(
String? sourceAccountId, String opPrefix, Map<String, String> map) {
String? fnType = _removeComment(map[opPrefix + 'function.type']);
Expand Down Expand Up @@ -1407,7 +1408,7 @@ class TxRep {
throw Exception('unknown $prefix' + 'type');
}
}

*/
static LiquidityPoolWithdrawOperation _getLiquidityPoolWithdrawOp(
String? sourceAccountId, String opPrefix, Map<String, String> map) {
String? liquidityPoolID = _removeComment(map[opPrefix + 'liquidityPoolID']);
Expand Down Expand Up @@ -3436,7 +3437,7 @@ class TxRep {
_addLine('$prefix.amount', _toAmount(operation.amount), lines);
_addLine('$prefix.minAmountA', _toAmount(operation.minAmountA), lines);
_addLine('$prefix.minAmountB', _toAmount(operation.minAmountB), lines);
} else if (operation is InvokeHostFunctionOperation) {
} /*else if (operation is InvokeHostFunctionOperation) {
String fnPrefix = prefix + ".function";
_addLine('$fnPrefix.type', _txRepInvokeHostFnType(operation.functionType),
lines);
Expand Down Expand Up @@ -3499,9 +3500,9 @@ class TxRep {
for (int i = 0; i < contractAuth.length; i++) {
_addContractAuth(contractAuth[i], lines, prefix + '.auth[$i]');
}
}
}*/
}

/*
static _addContractAuth(
XdrContractAuth auth, List<String> lines, String prefix) {
if (auth.addressWithNonce != null) {
Expand Down Expand Up @@ -3976,7 +3977,7 @@ class TxRep {
break;
}
}

*/
static _addClaimPredicate(
XdrClaimPredicate? predicate, List<String>? lines, String prefix) {
if (lines == null || predicate == null) return;
Expand Down Expand Up @@ -4037,6 +4038,7 @@ class TxRep {
}
}


static _addSignatures(List<XdrDecoratedSignature?>? signatures,
List<String>? lines, String prefix) {
if (lines == null) return;
Expand Down
21 changes: 9 additions & 12 deletions lib/src/soroban/soroban_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Address {

/// Returns a [XdrSCVal] containing an [XdrSCObject] for this [Address].
XdrSCVal toXdrSCVal() {
return XdrSCVal.forObject(XdrSCObject.forAddress(toXdr()));
return XdrSCVal.forAddress(toXdr());
}
}

Expand Down Expand Up @@ -225,8 +225,8 @@ class ContractAuth {
List<XdrSCVal> argsArr = List<XdrSCVal>.empty(growable: true);
if (xdr.signatureArgs.length > 0) {
XdrSCVal innerVal = xdr.signatureArgs[0];
if (innerVal.obj != null && innerVal.obj!.vec != null) {
argsArr = innerVal.obj!.vec!;
if (innerVal.vec != null) {
argsArr = innerVal.vec!;
} else {
argsArr = xdr.signatureArgs;
}
Expand Down Expand Up @@ -255,9 +255,7 @@ class ContractAuth {
// See: https://discord.com/channels/897514728459468821/1076723574884282398/1078095366890729595
List<XdrSCVal> sigArgs = List<XdrSCVal>.empty(growable: true);
if (signatureArgs.length > 0) {
XdrSCObject obj = XdrSCObject.forVec(signatureArgs);
XdrSCVal val = XdrSCVal.forObject(obj);
sigArgs.add(val);
sigArgs.add(XdrSCVal.forVec(signatureArgs));
}
return new XdrContractAuth(
addressWithNonce, rootInvocation.toXdr(), sigArgs);
Expand All @@ -281,13 +279,12 @@ class AccountEd25519Signature {
AccountEd25519Signature(this.publicKey, this.signatureBytes);

XdrSCVal toXdrSCVal() {
XdrSCObject pkObj = XdrSCObject.forBytes(publicKey.getEd25519()!.uint256);
XdrSCObject sigObj = XdrSCObject.forBytes(signatureBytes);
XdrSCVal pkVal = XdrSCVal.forBytes(publicKey.getEd25519()!.uint256);
XdrSCVal sigVal = XdrSCVal.forBytes(signatureBytes);
XdrSCMapEntry pkEntry = XdrSCMapEntry(
XdrSCVal.forSymbol("public_key"), XdrSCVal.forObject(pkObj));
XdrSCVal.forSymbol("public_key"), pkVal);
XdrSCMapEntry sigEntry = XdrSCMapEntry(
XdrSCVal.forSymbol("signature"), XdrSCVal.forObject(sigObj));
XdrSCObject resultObj = XdrSCObject.forMap([pkEntry, sigEntry]);
return XdrSCVal.forObject(resultObj);
XdrSCVal.forSymbol("signature"), sigVal);
return XdrSCVal.forMap([pkEntry, sigEntry]);
}
}
Loading

0 comments on commit e6ceaf6

Please sign in to comment.