Skip to content

Commit

Permalink
move state changes actions to separated package; refactoring (#64)
Browse files Browse the repository at this point in the history
* move state changes actions to separated package; refactoring

* update to [email protected]

* Node.compileScript(); upgrade to waves-transactions:1.0.1

* rename api methods

* rename TypeRef
  • Loading branch information
msmolyakov authored Sep 7, 2020
1 parent 0be52b0 commit 18611f0
Show file tree
Hide file tree
Showing 25 changed files with 509 additions and 952 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.0.0
- significantly redesigned interface
- based on [Waves Crypto](https://github.com/wavesplatform/waves-crypto-java) and [Waves transactions](https://github.com/wavesplatform/waves-transactions-java) libraries
- supported most of Waves Node API
- feature #15 of Waves Node 1.2 Malibu release is now supported

## 0.17.0
- new InvokeScriptTransactionStCh with stateChanges attribute was added. It was design to provide an additional information about Invocation transaction and couldn't be used to post invokes into blockchain. That why constructor was marked as package-private
- new AllTxIterator class to navigate over all account transactions. It has a generic semantic and can be used for other endpoints and transaction.
Expand Down
64 changes: 15 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# WavesJ
A Java library for interacting with the Waves blockchain.

Supports node interaction, offline transaction signing, Matcher orders, and creating addresses and keys.
Supports node interaction, offline transaction signing and creating addresses and keys.

## Using WavesJ in your project
Use the codes below to add WavesJ as a dependency for your project.
Expand All @@ -11,83 +11,49 @@ Use the codes below to add WavesJ as a dependency for your project.
<dependency>
<groupId>com.wavesplatform</groupId>
<artifactId>wavesj</artifactId>
<version>0.17.0</version>
<version>1.0.0</version>
</dependency>
```

##### Gradle:
```
compile group: 'com.wavesplatform', name: 'wavesj', version: '0.17.0'
compile group: 'com.wavesplatform', name: 'wavesj', version: '1.0.0'
```

##### SBT:
```
libraryDependencies += "com.wavesplatform" % "wavesj" % "0.17.0"
libraryDependencies += "com.wavesplatform" % "wavesj" % "1.0.0"
```

[This library's page at Maven Central](https://mvnrepository.com/artifact/com.wavesplatform/wavesj)

## Basic Usage
Create an account from a private key ('T' for testnet):
```java
String seed = "health lazy lens fix dwarf salad breeze myself silly december endless rent faculty report beyond";
PrivateKeyAccount account = PrivateKeyAccount.fromSeed(seed, 0, Account.TESTNET);
byte[] publicKey = account.getPublicKey();
String address = account.getAddress();
String seed = Crypto.getRandomSeedPhrase();
PrivateKey privateKey = PrivateKey.fromSeed(seed);
PublicKey publicKey = PublicKey.from(privateKey);
Address address = Address.from(publicKey);
```

Create a Node and learn a few things about blockchain:
```java
Node node = new Node("https://testnode2.wavesnodes.com/", Account.TESTNET);
Node node = new Node(Profile.MAINNET);
System.out.println("Current height is " + node.getHeight());
System.out.println("My balance is " + node.getBalance(address));
System.out.println("With 100 confirmations: " + node.getBalance(address, 100));
```

Send some money to a buddy:
```java
String buddy = "3N9gDFq8tKFhBDBTQxR3zqvtpXjw5wW3syA";
String txId = node.transfer(account, buddy, 1_00000000, 100_000, "Here's for you");
Address buddy = new Address("3N9gDFq8tKFhBDBTQxR3zqvtpXjw5wW3syA");
node.broadcast(TransferTransaction.builder(buddy, Amount.of(1_00000000, Asset.WAVES)).getSignedWith(privateKey));
```

Set a script on an account. Be careful with the script you pass here, as it may lock the account forever!
```java
String setScriptTxId = node.setScript(alice, "tx.type == 13 && height > " + height, Account.TESTNET, SCRIPT_FEE);
Base64String script = node
.compile("{-# CONTENT_TYPE EXPRESSION #-} sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)")
.script();
node.broadcast(new SetScriptTransaction(publicKey, script).addProof(privateKey));
```

Sign a transaction offline:
```java
Transaction tx = Transaction.makeTransferTx(account, buddy, 1_00000000, Asset.WAVES, 100_000, Asset.WAVES, "");
System.out.println("JSON encoded data: " + tx.getJson());
System.out.println("Server endpoint to send this JSON to: " + tx.getEndpoint());
```

Now send it from an online machine:
```java
node.send(tx);
```

Create a DEX order:
```java
Node matcher = new Node("https://testnode2.wavesnodes.com", Account.TESTNET);
String matcherKey = matcher.getMatcherKey();
String wbtcId = "Fmg13HEHJHuZYbtJq8Da8wifJENq8uBxDuWoP9pVe2Qe";
Order order = matcher.createOrder(alice, matcherKey,
new AssetPair(Asset.WAVES, wbtcId),
// buy 10 WAVES at 0.00090000 WBTC each
Order.Type.BUY, 90_000, 10 * Asset.TOKEN,
// make order valid for 1 hour
System.currentTimeMillis() + 3_600_000, MATCHER_FEE);
System.out.printf("Filed order " + order.id);
```
There are some examples under `src/examples/java`.

## Building the library

To build from scratch, prepare testnet account with 10 Waves and run

```
mvn clean package -DbenzPrivateKey=YourPrivateKeyOnTestnetWith10Waves
```

The outputs are placed under the `target` directory.
37 changes: 0 additions & 37 deletions examples/pom.xml

This file was deleted.

31 changes: 0 additions & 31 deletions examples/src/main/java/GRPCTest.java

This file was deleted.

104 changes: 0 additions & 104 deletions examples/src/main/java/NodeExample.java

This file was deleted.

Loading

0 comments on commit 18611f0

Please sign in to comment.