use of dev.jlibra.client.DiemClient in project jlibra by ketola.
the class GetAccountStateExample method main.
public static void main(String[] args) throws Exception {
String address = "79153273a34e0aadf26c963367973760";
DiemClient client = DiemClient.builder().withUrl("https://testnet.diem.com/v1").build();
Account accountView = client.getAccount(AccountAddress.fromHexString(address));
logger.info("Account: {}", accountView);
}
use of dev.jlibra.client.DiemClient in project jlibra by ketola.
the class GetEventsByEventKeyExample method main.
public static void main(String[] args) {
String eventKey = "00000000000000000000000000000000000000000a550c18";
DiemClient client = DiemClient.builder().withUrl("https://testnet.diem.com/v1").build();
List<Event> events = client.getEvents(eventKey, 0, 10);
events.forEach(e -> logger.info("Event: {}", e));
}
use of dev.jlibra.client.DiemClient in project jlibra by ketola.
the class GetStateProofExample method main.
public static void main(String[] args) {
DiemClient client = DiemClient.builder().withUrl("https://testnet.diem.com/v1").build();
StateProof stateProof = client.getStateProof(324);
logger.info("State proof: {}", stateProof);
}
use of dev.jlibra.client.DiemClient in project jlibra by ketola.
the class MintExample method main.
public static void main(String[] args) {
AuthenticationKey authenticationKey = AuthenticationKey.fromHexString("8f30171675008e598af4d57c159dad7240fc2800a33e1790730244ab931630a2");
Faucet faucet = Faucet.builder().build();
faucet.mint(authenticationKey, 100L * 1_000_000L, CURRENCY);
DiemClient client = DiemClient.builder().withUrl("http://testnet.diem.com/v1").build();
Wait.until(accountHasPositiveBalance(AccountAddress.fromAuthenticationKey(authenticationKey), client));
Account account = client.getAccount(AccountAddress.fromAuthenticationKey(authenticationKey));
logger.info("Balance: {} {}", account.balances().get(0).amount() / 1_000_000, account.balances().get(0).currency());
}
use of dev.jlibra.client.DiemClient in project jlibra by ketola.
the class TransferExample method main.
public static void main(String[] args) {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
DiemClient client = DiemClient.builder().withUrl("https://testnet.diem.com/v1").build();
PrivateKey privateKey = KeyUtils.privateKeyFromByteSequence(ByteArray.from("3051020101300506032b657004220420aeff20e881cd4c7f32b23b74ab6c9ffce5b2764047d141b1c84e47f6c3b656d08121006495a72dd63c25c3173eeaa9b5f5c03050a669b4845db67f779f8d8839911562"));
PublicKey publicKey = PublicKey.fromHexString("302a300506032b65700321006495a72dd63c25c3173eeaa9b5f5c03050a669b4845db67f779f8d8839911562");
AuthenticationKey authenticationKey = AuthenticationKey.fromPublicKey(publicKey);
AccountAddress sourceAccount = AccountAddress.fromAuthenticationKey(authenticationKey);
logger.info("Source account authentication key: {}, address: {}", authenticationKey, sourceAccount);
Account accountState = client.getAccount(sourceAccount);
// If the account already exists, then the authentication key of the target
// account is not required and the account address would be enough
AuthenticationKey authenticationKeyTarget = AuthenticationKey.fromHexString("37b1b993c4d932b6830332d01f3cde4afe7f9fc36a7b207ef8960d2b81259180");
long amount = 1;
long sequenceNumber = accountState.sequenceNumber();
logger.info("Sending from {} to {}", AccountAddress.fromAuthenticationKey(authenticationKey), AccountAddress.fromAuthenticationKey(authenticationKeyTarget));
// Arguments for the peer to peer transaction
U64Argument amountArgument = U64Argument.from(amount * 1000000);
AccountAddressArgument addressArgument = AccountAddressArgument.from(AccountAddress.fromAuthenticationKey(authenticationKeyTarget));
U8VectorArgument metadataArgument = U8VectorArgument.from(ByteArray.from("This is the metadata, you can put anything here!".getBytes(UTF_8)));
// signature can be used for approved transactions, we are not doing that and
// can set the signature as an empty byte array
U8VectorArgument signatureArgument = U8VectorArgument.from(ByteArray.from(new byte[0]));
Transaction transaction = ImmutableTransaction.builder().sequenceNumber(sequenceNumber).maxGasAmount(1640000).gasCurrencyCode(CURRENCY).gasUnitPrice(1).sender(sourceAccount).expirationTimestampSecs(Instant.now().getEpochSecond() + 60).payload(ImmutableScript.builder().typeArguments(asList(Struct.typeTagForCurrency(CURRENCY))).code(Move.peerToPeerTransferWithMetadata()).addArguments(addressArgument, amountArgument, metadataArgument, signatureArgument).build()).chainId(ChainId.DEVNET).build();
SignedTransaction signedTransaction = ImmutableSignedTransaction.builder().authenticator(ImmutableTransactionAuthenticatorEd25519.builder().publicKey(publicKey).signature(Signature.signTransaction(transaction, privateKey)).build()).transaction(transaction).build();
client.submit(signedTransaction);
// get the transaction and read the metadata
Wait.until(transactionFound(AccountAddress.fromAuthenticationKey(authenticationKey), sequenceNumber, client));
UserTransaction t = (UserTransaction) client.getAccountTransaction(sourceAccount, sequenceNumber, true).transaction();
PeerToPeerWithMetadataScript script = (PeerToPeerWithMetadataScript) t.script();
logger.info("Metadata: {}", new String(Hex.decode(script.metadata())));
}
Aggregations