Skip to content

Commit

Permalink
Merge pull request #13 from Jay-Tezsure/Deploy-a-Contract
Browse files Browse the repository at this point in the history
Release beta 2.1.0+1
  • Loading branch information
aditya-tezsure authored Feb 18, 2021
2 parents 952428f + c15460f commit 9b2aed7
Show file tree
Hide file tree
Showing 26 changed files with 5,396 additions and 32 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [2.1.0+1]

* Deploy contract
* Call contract
* Operation confirmation
* Fix for revelation of an account Ref #12

# [2.0.0]

* Dependencies update.
Expand All @@ -18,4 +25,4 @@ Initial version of library.
* Generate keys from mnemonic.
* Generate keys from mnemonics and passphrase.
* Sign Operation Group.
* Unlock fundraiser identity.
* Unlock fundraiser identity.
149 changes: 148 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Tezos is a decentralized blockchain that governs itself by establishing a true d
* Unlock fundraiser identity.
* Transfer Balance.
* Delegate an Account.
* Deploy a contract.
* Call a contract.
* Operation confirmation.

### Getting started

Expand Down Expand Up @@ -154,6 +157,150 @@ print("Operation groupID ===> $result['operationGroupID']");
```

* Deploy a contract.
* With this release we are excited to include the feature of trestles chain interactions, including contract deployment a user can directly write smart contracts in Michelson language and deploy it on Tezos chain using the `sendContractOriginationOperation()` method in return you'll get an origination id of the deployed contract that can be use to track the contract on chain. We have set an example for you below.

``` dart
var server = '';
var contract = """parameter string;
storage string;
code { DUP;
DIP { CDR ; NIL string ; SWAP ; CONS } ;
CAR ; CONS ;
CONCAT;
NIL operation; PAIR}""";
var storage = '"Sample"';
var keyStore = KeyStoreModel(
publicKey: 'edpkvQtuhdZQmjdjVfaY9Kf4hHfrRJYugaJErkCGvV3ER1S7XWsrrj',
secretKey:
'edskRgu8wHxjwayvnmpLDDijzD3VZDoAH7ZLqJWuG4zg7LbxmSWZWhtkSyM5Uby41rGfsBGk4iPKWHSDniFyCRv3j7YFCknyHH',
publicKeyHash: 'tz1QSHaKpTFhgHLbqinyYRjxD5sLcbfbzhxy',
);
var signer = await TezsterDart.createSigner(
TezsterDart.writeKeyWithHint(keyStore.secretKey, 'edsk'));
var result = await TezsterDart.sendContractOriginationOperation(
server,
signer,
keyStore,
0,
null,
100000,
1000,
100000,
contract,
storage,
codeFormat: TezosParameterFormat.Michelson,
);
print("Operation groupID ===> $result['operationGroupID']");
```
reference link: `https://github.com/Tezsure/Tezster_dart/blob/master/example/lib/main.dart#L110`
<br>

* Call a contract.
* We have also included the feature to call or invoke a deployed contract just use the inbuilt `sendContractInvocationOperation()` method in return you'll get an origination id of the invoked contract that can be used to track the contracts on chain. We have set an example for you below.

``` dart
var server = '';
var keyStore = KeyStoreModel(
publicKey: 'edpkvQtuhdZQmjdjVfaY9Kf4hHfrRJYugaJErkCGvV3ER1S7XWsrrj',
secretKey:
'edskRgu8wHxjwayvnmpLDDijzD3VZDoAH7ZLqJWuG4zg7LbxmSWZWhtkSyM5Uby41rGfsBGk4iPKWHSDniFyCRv3j7YFCknyHH',
publicKeyHash: 'tz1QSHaKpTFhgHLbqinyYRjxD5sLcbfbzhxy',
);
var signer = await TezsterDart.createSigner(
TezsterDart.writeKeyWithHint(keyStore.secretKey, 'edsk'));
var contractAddress = 'KT1KA7DqFjShLC4CPtChPX8QtRYECUb99xMY';
var resultInvoke = await TezsterDart.sendContractInvocationOperation(
server,
signer,
keyStore,
contractAddress,
10000,
100000,
1000,
100000,
'',
'"Cryptonomicon"',
codeFormat: TezosParameterFormat.Michelson);
print("Operation groupID ===> $result['operationGroupID']");
```
reference link: `https://github.com/Tezsure/Tezster_dart/blob/master/example/lib/main.dart#L141`
<br>

* Operation confirmation.
* No wonder it's really important to await for confirmation for any on chain interactions. Hence, we have provided `awaitOperationConfirmation()` method with this release that developers can leverage for their advantage to confirm the originated contract's operations id. We have set an example for you how to use it.

``` dart
var server = '';
var network = 'carthagenet';
var serverInfo = {
'url': '',
'apiKey': '',
'network': network
};
var contract = """parameter string;
storage string;
code { DUP;
DIP { CDR ; NIL string ; SWAP ; CONS } ;
CAR ; CONS ;
CONCAT;
NIL operation; PAIR}""";
var storage = '"Sample"';
var keyStore = KeyStoreModel(
publicKey: 'edpkvQtuhdZQmjdjVfaY9Kf4hHfrRJYugaJErkCGvV3ER1S7XWsrrj',
secretKey:
'edskRgu8wHxjwayvnmpLDDijzD3VZDoAH7ZLqJWuG4zg7LbxmSWZWhtkSyM5Uby41rGfsBGk4iPKWHSDniFyCRv3j7YFCknyHH',
publicKeyHash: 'tz1QSHaKpTFhgHLbqinyYRjxD5sLcbfbzhxy',
);
var signer = await TezsterDart.createSigner(
TezsterDart.writeKeyWithHint(keyStore.secretKey, 'edsk'));
var result = await TezsterDart.sendContractOriginationOperation(
server,
signer,
keyStore,
0,
null,
100000,
1000,
100000,
contract,
storage,
codeFormat: TezosParameterFormat.Michelson,
);
print("Operation groupID ===> $result['operationGroupID']");
var groupId = result['operationGroupID'];
var conseilResult = await TezsterDart.awaitOperationConfirmation(
serverInfo, network, groupId, 5);
print('Originated contract at ${conseilResult['originated_contracts']}');
```
reference link: `https://github.com/Tezsure/Tezster_dart/blob/master/example/lib/main.dart#L162`
<br>

---
**NOTE:**
Use stable version of flutter to avoid package conflicts.
Expand All @@ -162,4 +309,4 @@ Use stable version of flutter to avoid package conflicts.

### Feature requests and bugs

Please file feature requests and bugs at the [issue tracker](https://github.com/Tezsure/tezster_dart/issues/new). If you want to contribute to this libary, please submit a Pull Request.
Please file feature requests and bugs at the [issue tracker](https://github.com/Tezsure/tezster_dart/issues/new). If you want to contribute to this libary, please submit a Pull Request.
85 changes: 85 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,91 @@ class _MyAppState extends State<MyApp> {
);
print("Applied operation ===> $delegationResult['appliedOp']");
print("Operation groupID ===> $delegationResult['operationGroupID']");

//Deploy a contract
var contract = """parameter string;
storage string;
code { DUP;
DIP { CDR ; NIL string ; SWAP ; CONS } ;
CAR ; CONS ;
CONCAT;
NIL operation; PAIR}""";

var storage = '"Sample"';
var contractOriginationSigner = await TezsterDart.createSigner(
TezsterDart.writeKeyWithHint(keyStore.secretKey, 'edsk'));

var resultContractOrigination =
await TezsterDart.sendContractOriginationOperation(
server,
contractOriginationSigner,
keyStore,
0,
null,
100000,
1000,
100000,
contract,
storage,
codeFormat: TezosParameterFormat.Michelson,
);

print(
"Operation groupID ===> $resultContractOrigination['operationGroupID']");

//Call a contract
var contractInvocationSigner = await TezsterDart.createSigner(
TezsterDart.writeKeyWithHint(keyStore.secretKey, 'edsk'));

var contractAddress = 'KT1KA7DqFjShLC4CPtChPX8QtRYECUb99xMY';

var resultInvoke = await TezsterDart.sendContractInvocationOperation(
server,
contractInvocationSigner,
keyStore,
contractAddress,
10000,
100000,
1000,
100000,
'',
'"Cryptonomicon"',
codeFormat: TezosParameterFormat.Michelson);

print("Operation groupID ===> $resultInvoke['operationGroupID']");

//Await opration Confirmation
var network = 'carthagenet';

var serverInfo = {'url': '', 'apiKey': '', 'network': network};

var operationConfirmationSigner = await TezsterDart.createSigner(
TezsterDart.writeKeyWithHint(keyStore.secretKey, 'edsk'));

var resultoperationConfirmation =
await TezsterDart.sendContractOriginationOperation(
server,
operationConfirmationSigner,
keyStore,
0,
null,
100000,
1000,
100000,
contract,
storage,
codeFormat: TezosParameterFormat.Michelson,
);

print(
"Operation groupID ===> $resultoperationConfirmation['operationGroupID']");

var groupId = resultoperationConfirmation['operationGroupID'];

var conseilResult = await TezsterDart.awaitOperationConfirmation(
serverInfo, network, groupId, 5);

print('Originated contract at ${conseilResult['originated_contracts']}');
}

@override
Expand Down
8 changes: 4 additions & 4 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ packages:
name: bip39
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
version: "1.0.4"
blake2b:
dependency: transitive
description:
Expand Down Expand Up @@ -117,7 +117,7 @@ packages:
name: flutter_sodium
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.9"
version: "0.1.11"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -164,7 +164,7 @@ packages:
name: pointycastle
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
version: "2.0.1"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -218,7 +218,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.0.0"
version: "2.1.0+1"
typed_data:
dependency: transitive
description:
Expand Down
14 changes: 14 additions & 0 deletions lib/chain/tezos/tezos_language_util.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import 'package:tezster_dart/michelson_parser/michelson_parser.dart';

class TezosLanguageUtil {
static String translateMichelsonToMicheline(String code) {
// jsonDecode()
var result = MichelsonParser.parseMichelson(code);
return result;
}

static String translateMichelineToHex(p) {
return MichelsonParser.translateMichelineToHex(p);
}
}
Loading

0 comments on commit 9b2aed7

Please sign in to comment.