-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make Faucet contracts available in development;
add toBounceableTestnet() and toNonBounceableTestnet() to Address;
- Loading branch information
Showing
35 changed files
with
3,451 additions
and
3,207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
smartcontract/src/main/java/org/ton/java/smartcontract/faucet/TestnetFaucet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.ton.java.smartcontract.faucet; | ||
|
||
import static java.util.Objects.isNull; | ||
|
||
import com.iwebpp.crypto.TweetNaclFast; | ||
import java.math.BigInteger; | ||
import org.ton.java.address.Address; | ||
import org.ton.java.smartcontract.types.WalletV1R3Config; | ||
import org.ton.java.smartcontract.wallet.ContractUtils; | ||
import org.ton.java.smartcontract.wallet.v1.WalletV1R3; | ||
import org.ton.java.tonlib.Tonlib; | ||
import org.ton.java.tonlib.types.ExtMessageInfo; | ||
import org.ton.java.utils.Utils; | ||
|
||
public class TestnetFaucet { | ||
|
||
public static String PUBLIC_KEY = | ||
"c02ece00eceb299066597ccc7a8ac0b2d08f0ad425f28c0ea92e74e2064f41f0"; | ||
static String SECRET_KEY = | ||
"46aab91daaaa375d40588384fdf7e36c62d0c0f38c46adfea7f9c904c5973d97c02ece00eceb299066597ccc7a8ac0b2d08f0ad425f28c0ea92e74e2064f41f0"; | ||
public static String FAUCET_ADDRESS_RAW = | ||
"0:b52a16ba3735501df19997550e7ed4c41754ee501ded8a841088ce4278b66de4"; | ||
public static String NON_BOUNCEABLE = "0QC1Kha6NzVQHfGZl1UOftTEF1TuUB3tioQQiM5CeLZt5FIA"; | ||
public static String BOUNCEABLE = "kQC1Kha6NzVQHfGZl1UOftTEF1TuUB3tioQQiM5CeLZt5A_F"; | ||
|
||
public static BigInteger topUpContract( | ||
Tonlib tonlib, Address destinationAddress, BigInteger amount) throws InterruptedException { | ||
|
||
if (amount.compareTo(Utils.toNano(20)) > 0) { | ||
throw new Error( | ||
"Too many TONs requested from the TestnetFaucet, maximum amount per request is 20."); | ||
} | ||
|
||
TweetNaclFast.Signature.KeyPair keyPair = | ||
TweetNaclFast.Signature.keyPair_fromSeed(Utils.hexToSignedBytes(SECRET_KEY)); | ||
|
||
WalletV1R3 faucet = WalletV1R3.builder().tonlib(tonlib).keyPair(keyPair).build(); | ||
|
||
BigInteger faucetBalance = null; | ||
int i = 0; | ||
do { | ||
try { | ||
if (i++ > 10) { | ||
throw new Error("Cannot get faucet balance. Restart."); | ||
} | ||
|
||
faucetBalance = faucet.getBalance(); | ||
System.out.println( | ||
"Faucet address " | ||
+ faucet.getAddress().toBounceable() | ||
+ ", balance " | ||
+ Utils.formatNanoValue(faucetBalance)); | ||
if (faucetBalance.compareTo(amount) < 0) { | ||
throw new Error( | ||
"Faucet does not have that much toncoins. faucet balance " | ||
+ Utils.formatNanoValue(faucetBalance) | ||
+ ", requested " | ||
+ Utils.formatNanoValue(amount)); | ||
} | ||
} catch (Exception e) { | ||
System.out.println("Cannot get faucet balance. Restarting..."); | ||
Utils.sleep(5, "Waiting for faucet balance"); | ||
} | ||
} while (isNull(faucetBalance)); | ||
|
||
WalletV1R3Config config = | ||
WalletV1R3Config.builder() | ||
.bounce(false) | ||
.seqno(faucet.getSeqno()) | ||
.destination(destinationAddress) | ||
.amount(amount) | ||
.comment("top-up from ton4j faucet") | ||
.build(); | ||
|
||
ExtMessageInfo extMessageInfo = faucet.send(config); | ||
|
||
if (extMessageInfo.getError().getCode() != 0) { | ||
throw new Error(extMessageInfo.getError().getMessage()); | ||
} | ||
|
||
ContractUtils.waitForBalanceChange(tonlib, destinationAddress, 120); | ||
|
||
return tonlib.getAccountBalance(destinationAddress); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
smartcontract/src/main/java/org/ton/java/smartcontract/faucet/TestnetJettonFaucet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.ton.java.smartcontract.faucet; | ||
|
||
import com.iwebpp.crypto.TweetNaclFast; | ||
import java.math.BigInteger; | ||
import org.ton.java.address.Address; | ||
import org.ton.java.smartcontract.token.ft.JettonMinter; | ||
import org.ton.java.smartcontract.token.ft.JettonWallet; | ||
import org.ton.java.smartcontract.types.WalletV3Config; | ||
import org.ton.java.smartcontract.utils.MsgUtils; | ||
import org.ton.java.smartcontract.wallet.ContractUtils; | ||
import org.ton.java.smartcontract.wallet.v3.WalletV3R2; | ||
import org.ton.java.tonlib.Tonlib; | ||
import org.ton.java.tonlib.types.ExtMessageInfo; | ||
import org.ton.java.utils.Utils; | ||
|
||
/** Faucet for NEOJ jettons. */ | ||
public class TestnetJettonFaucet { | ||
|
||
public static String ADMIN_WALLET_PUBLIC_KEY = | ||
"d1d4515b2635b81de98d58f65502f2c242bb0e63615520341b83a12dd4d0f516"; | ||
static String ADMIN_WALLET_SECRET_KEY = | ||
"be0bbb1725807ec0df984702a32a143864418400d797a48e267a120c3dc5f8d0d1d4515b2635b81de98d58f65502f2c242bb0e63615520341b83a12dd4d0f516"; | ||
public static String ADMIN_WALLET_ADDRESS = | ||
"0:98972d1ab4b86f6be34ad03d64bb5e2cb369f0d7b5e53f13348664672b893010"; | ||
public static String ADMIN_WALLET_BOUNCEABLE_ADDRESS = | ||
"EQCYly0atLhva-NK0D1ku14ss2nw17XlPxM0hmRnK4kwEO86"; | ||
public static String FAUCET_MASTER_ADDRESS = "kQAN6TAGauShFKDQvZCwNb_EeTUIjQDwRZ9t6GOn4FBzfg9Y"; | ||
|
||
public static BigInteger topUpContractWithNeoj( | ||
Tonlib tonlib, Address destinationAddress, BigInteger jettonsAmount) { | ||
|
||
if (jettonsAmount.compareTo(Utils.toNano(100)) > 0) { | ||
throw new Error( | ||
"Too many NEOJ jettons requested from the TestnetJettonFaucet, maximum amount per request is 100."); | ||
} | ||
|
||
TweetNaclFast.Signature.KeyPair keyPair = | ||
TweetNaclFast.Signature.keyPair_fromSeed(Utils.hexToSignedBytes(ADMIN_WALLET_SECRET_KEY)); | ||
|
||
WalletV3R2 adminWallet = | ||
WalletV3R2.builder().tonlib(tonlib).walletId(42).keyPair(keyPair).build(); | ||
|
||
JettonMinter jettonMinterWallet = | ||
JettonMinter.builder() | ||
.tonlib(tonlib) | ||
.customAddress(Address.of(FAUCET_MASTER_ADDRESS)) | ||
.build(); | ||
|
||
JettonWallet adminJettonWallet = jettonMinterWallet.getJettonWallet(adminWallet.getAddress()); | ||
|
||
WalletV3Config walletV3Config = | ||
WalletV3Config.builder() | ||
.walletId(42) | ||
.seqno(adminWallet.getSeqno()) | ||
.destination(adminJettonWallet.getAddress()) | ||
.amount(Utils.toNano(0.06)) | ||
.body( | ||
JettonWallet.createTransferBody( | ||
0, | ||
jettonsAmount, | ||
destinationAddress, // recipient | ||
adminWallet.getAddress(), // response address | ||
null, // custom payload | ||
BigInteger.ONE, // forward amount | ||
MsgUtils.createTextMessageBody( | ||
"jetton top up from ton4j faucet") // forward payload | ||
)) | ||
.build(); | ||
ExtMessageInfo extMessageInfo = adminWallet.send(walletV3Config); | ||
|
||
if (extMessageInfo.getError().getCode() != 0) { | ||
throw new Error(extMessageInfo.getError().getMessage()); | ||
} | ||
|
||
ContractUtils.waitForJettonBalanceChange( | ||
tonlib, Address.of(FAUCET_MASTER_ADDRESS), adminWallet.getAddress(), 60); | ||
Utils.sleep(10); | ||
return ContractUtils.getJettonBalance( | ||
tonlib, Address.of(FAUCET_MASTER_ADDRESS), destinationAddress); | ||
} | ||
} |
Oops, something went wrong.