Skip to content

Commit

Permalink
refactoring, synthetic sugar, documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
neodix42 committed Mar 2, 2023
1 parent 47836f7 commit 89bad30
Show file tree
Hide file tree
Showing 49 changed files with 844 additions and 190 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Do not forget to place tonlibjson library to your project. Latest Tonlib librari
<dependency>
<groupId>io.github.neodix42</groupId>
<artifactId>smartcontract</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</dependency>
```

Expand All @@ -32,7 +32,7 @@ Do not forget to place tonlibjson library to your project. Latest Tonlib librari
<dependency>
<groupId>io.github.neodix42</groupId>
<artifactId>ton4j</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</dependency>
```

Expand Down
4 changes: 2 additions & 2 deletions address/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<dependency>
<groupId>io.github.neodix42</groupId>
<artifactId>address</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</dependency>
```

Expand All @@ -17,7 +17,7 @@
<dependency>
<groupId>io.github.neodix42.ton4j</groupId>
<artifactId>address</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion address/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.neodix42</groupId>
<artifactId>top</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
4 changes: 2 additions & 2 deletions bitstring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<dependency>
<groupId>io.github.neodix42</groupId>
<artifactId>bitstring</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</dependency>
```

Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>io.github.neodix42.ton4j</groupId>
<artifactId>bitstring</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion bitstring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.neodix42</groupId>
<artifactId>top</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
4 changes: 2 additions & 2 deletions cell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<dependency>
<groupId>io.github.neodix42</groupId>
<artifactId>cell</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</dependency>
```

Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>io.github.neodix42.ton4j</groupId>
<artifactId>cell</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion cell/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.neodix42</groupId>
<artifactId>top</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
4 changes: 2 additions & 2 deletions mnemonic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<dependency>
<groupId>io.github.neodix42</groupId>
<artifactId>mnemonic</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</dependency>
```

Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>io.github.neodix42.ton4j</groupId>
<artifactId>mnemonic</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion mnemonic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>top</artifactId>
<groupId>io.github.neodix42</groupId>
<version>0.1.0</version>
<version>0.1.1</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.github.neodix42</groupId>
<artifactId>top</artifactId>
<packaging>pom</packaging>
<version>0.1.0</version>
<version>0.1.1</version>

<modules>
<module>bitstring</module>
Expand Down
4 changes: 2 additions & 2 deletions smartcontract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<dependency>
<groupId>io.github.neodix42</groupId>
<artifactId>smartcontract</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</dependency>
```

Expand All @@ -18,7 +18,7 @@
<dependency>
<groupId>io.github.neodix42.ton4j</groupId>
<artifactId>smartcontract</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion smartcontract/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.github.neodix42</groupId>
<artifactId>top</artifactId>
<version>0.1.0</version>
<version>0.1.1</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ public void deploy(Tonlib tonlib, WalletContract wallet, BigInteger msgValue, Tw
seqno,
payload.endCell(),
(byte) 3, //send mode
false, //dummy signature
this.createStateInit().stateInit
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.math.BigInteger;

import static java.util.Objects.nonNull;

public class HighloadWallet implements WalletContract {

//https://github.com/ton-blockchain/ton/blob/master/crypto/smartcont/highload-wallet-v2-code.fc
Expand Down Expand Up @@ -113,7 +115,7 @@ public String getPublicKey(Tonlib tonlib) {
*/
public void sendTonCoins(Tonlib tonlib, byte[] secretKey, HighloadConfig highloadConfig) {
Cell signingMessageAll = createSigningMessageInternal(highloadConfig);
ExternalMessage msg = createExternalMessage(signingMessageAll, secretKey, 1, false);
ExternalMessage msg = createExternalMessage(signingMessageAll, secretKey, 1);
tonlib.sendRawMessage(msg.message.toBocBase64(false));
}

Expand All @@ -125,7 +127,12 @@ private Cell createDict(HighloadConfig highloadConfig) {
for (Destination destination : highloadConfig.getDestinations()) {

Cell orderHeader = Contract.createInternalMessageHeader(destination.getAddress(), destination.getAmount());
Cell order = Contract.createCommonMsgInfo(orderHeader);
Cell order;
if (nonNull(destination.getComment())) {
order = Contract.createCommonMsgInfo(orderHeader, null, CellBuilder.beginCell().storeUint(0, 32).storeString(destination.getComment()).endCell());
} else {
order = Contract.createCommonMsgInfo(orderHeader);
}

CellBuilder p = CellBuilder.beginCell();
p.storeUint(destination.getMode(), 8); // mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,109 @@ public long getSeqno(Tonlib tonlib) {
return seqno.getNumber().longValue();
}

public void deploy(Tonlib tonlib, byte[] secretKey) {
tonlib.sendRawMessage(createInitExternalMessage(secretKey).message.toBocBase64(false));
}

/**
* Sends amount of toncoins to destination address using auto-fetched seqno without the body and default send-mode 3
*
* @param tonlib Tonlib
* @param secretKey byte[]
* @param destinationAddress Address
* @param amount BigInteger
*/
public void sendTonCoins(Tonlib tonlib, byte[] secretKey, Address destinationAddress, BigInteger amount) {
long seqno = getSeqno(tonlib);
ExternalMessage msg = createTransferMessage(secretKey, destinationAddress, amount, seqno);
tonlib.sendRawMessage(Utils.bytesToBase64(msg.message.toBoc(false)));
}

public void deploy(Tonlib tonlib, byte[] secretKey) {
tonlib.sendRawMessage(createInitExternalMessage(secretKey).message.toBocBase64(false));
/**
* Sends amount of toncoins to destination address using specified seqno with the body and default send-mode 3
*
* @param tonlib Tonlib
* @param secretKey byte[]
* @param destinationAddress Address
* @param amount BigInteger
* @param body byte[]
*/
public void sendTonCoins(Tonlib tonlib, byte[] secretKey, Address destinationAddress, BigInteger amount, long seqno, byte[] body) {
ExternalMessage msg = createTransferMessage(secretKey, destinationAddress, amount, seqno, body);
tonlib.sendRawMessage(msg.message.toBocBase64(false));
}

/**
* Sends amount of toncoins to destination address using specified seqno with the body and specified send-mode
*
* @param tonlib Tonlib
* @param secretKey byte[]
* @param destinationAddress Address
* @param amount BigInteger
* @param body byte[]
* @param sendMode byte
*/
public void sendTonCoins(Tonlib tonlib, byte[] secretKey, Address destinationAddress, BigInteger amount, long seqno, byte[] body, byte sendMode) {
ExternalMessage msg = createTransferMessage(secretKey, destinationAddress, amount, seqno, body, sendMode);
tonlib.sendRawMessage(msg.message.toBocBase64(false));
}

/**
* Sends amount of toncoins to destination address using auto-fetched seqno with the body and default send-mode 3
*
* @param tonlib Tonlib
* @param secretKey byte[]
* @param destinationAddress Address
* @param amount BigInteger
* @param body byte[]
*/
public void sendTonCoins(Tonlib tonlib, byte[] secretKey, Address destinationAddress, BigInteger amount, byte[] body) {
long seqno = getSeqno(tonlib);
ExternalMessage msg = createTransferMessage(secretKey, destinationAddress, amount, seqno, body);
tonlib.sendRawMessage(msg.message.toBocBase64(false));
}

/**
* Sends amount of toncoins to destination address using specified seqno with the body and default send-mode 3
*
* @param tonlib Tonlib
* @param secretKey byte[]
* @param destinationAddress Address
* @param amount BigInteger
* @param comment String
*/
public void sendTonCoins(Tonlib tonlib, byte[] secretKey, Address destinationAddress, BigInteger amount, long seqno, String comment) {
ExternalMessage msg = createTransferMessage(secretKey, destinationAddress, amount, seqno, CellBuilder.beginCell().storeUint(0, 32).storeString(comment).endCell());
tonlib.sendRawMessage(msg.message.toBocBase64(false));
}

/**
* Sends amount of toncoins to destination address using auto-fetched seqno with the comment and default send-mode 3
*
* @param tonlib Tonlib
* @param secretKey byte[]
* @param destinationAddress Address
* @param amount BigInteger
* @param comment String
*/
public void sendTonCoins(Tonlib tonlib, byte[] secretKey, Address destinationAddress, BigInteger amount, String comment) {
long seqno = getSeqno(tonlib);
ExternalMessage msg = createTransferMessage(secretKey, destinationAddress, amount, seqno, CellBuilder.beginCell().storeUint(0, 32).storeString(comment).endCell());
tonlib.sendRawMessage(msg.message.toBocBase64(false));
}

/**
* Sends amount of toncoins to destination address using auto-fetched seqno with the body and specified send-mode
*
* @param tonlib Tonlib
* @param secretKey byte[]
* @param destinationAddress Address
* @param amount BigInteger
* @param body byte[]
*/
public void sendTonCoins(Tonlib tonlib, byte[] secretKey, Address destinationAddress, BigInteger amount, byte[] body, byte sendMode) {
long seqno = getSeqno(tonlib);
ExternalMessage msg = createTransferMessage(secretKey, destinationAddress, amount, seqno, body, sendMode);
tonlib.sendRawMessage(msg.message.toBocBase64(false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public ExternalMessage createExtMsg(Cell payload, boolean needStateInit, BigInte
seqno,
payload, // body
(byte) 3,
false,
stateInit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ public void deploy(Tonlib tonlib, WalletContract adminWallet, BigInteger walletM
seqno,
(Cell) null, // body
(byte) 3, //send mode
false, //dummy signature
this.createStateInit().stateInit);

tonlib.sendRawMessage(Utils.bytesToBase64(extMsg.message.toBoc(false)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ public void deploy(Tonlib tonlib, WalletContract wallet, BigInteger msgValue, Tw
seqno,
payload,
(byte) 3, //send mode
false, //dummy signature
this.createStateInit().stateInit
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public void deploy(Tonlib tonlib, WalletContract wallet, BigInteger msgValue, Tw
seqno,
payload,
(byte) 3, //send mode
false, //dummy signature
this.createStateInit().stateInit
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public class Destination {
byte mode; // default mode 3
Address address;
BigInteger amount;
String comment;
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ default Cell createInternalMessageHeader(String dest,
createdLt, createdAt);
}

static Cell createInternalMessageHeader(Address dest, BigInteger gramValue) {
static Cell createInternalMessageHeader(Address dest, BigInteger toncoinValue) {
return createInternalMessageHeader(
dest,
gramValue,
toncoinValue,
true,
null,
false,
Expand All @@ -198,10 +198,10 @@ static Cell createInternalMessageHeader(Address dest, BigInteger gramValue) {
BigInteger.ZERO);
}

static Cell createInternalMessageHeader(String dest, BigInteger gramValue) {
static Cell createInternalMessageHeader(String dest, BigInteger toncoinValue) {
return createInternalMessageHeader(
Address.of(dest),
gramValue,
toncoinValue,
true,
null,
false,
Expand Down
Loading

0 comments on commit 89bad30

Please sign in to comment.