Search in sources :

Example 1 with DiemClient

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);
}
Also used : DiemClient(dev.jlibra.client.DiemClient) Account(dev.jlibra.client.views.Account)

Example 2 with DiemClient

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));
}
Also used : DiemClient(dev.jlibra.client.DiemClient) Event(dev.jlibra.client.views.event.Event)

Example 3 with DiemClient

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);
}
Also used : DiemClient(dev.jlibra.client.DiemClient) StateProof(dev.jlibra.client.views.StateProof)

Example 4 with DiemClient

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());
}
Also used : DiemClient(dev.jlibra.client.DiemClient) Account(dev.jlibra.client.views.Account) AuthenticationKey(dev.jlibra.AuthenticationKey) Faucet(dev.jlibra.faucet.Faucet)

Example 5 with DiemClient

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())));
}
Also used : UserTransaction(dev.jlibra.client.views.transaction.UserTransaction) Account(dev.jlibra.client.views.Account) AccountAddressArgument(dev.jlibra.transaction.argument.AccountAddressArgument) PrivateKey(java.security.PrivateKey) U8VectorArgument(dev.jlibra.transaction.argument.U8VectorArgument) PublicKey(dev.jlibra.PublicKey) AccountAddress(dev.jlibra.AccountAddress) DiemClient(dev.jlibra.client.DiemClient) ImmutableTransaction(dev.jlibra.transaction.ImmutableTransaction) UserTransaction(dev.jlibra.client.views.transaction.UserTransaction) ImmutableSignedTransaction(dev.jlibra.transaction.ImmutableSignedTransaction) SignedTransaction(dev.jlibra.transaction.SignedTransaction) Transaction(dev.jlibra.transaction.Transaction) AuthenticationKey(dev.jlibra.AuthenticationKey) PeerToPeerWithMetadataScript(dev.jlibra.client.views.transaction.PeerToPeerWithMetadataScript) U64Argument(dev.jlibra.transaction.argument.U64Argument) ImmutableSignedTransaction(dev.jlibra.transaction.ImmutableSignedTransaction) SignedTransaction(dev.jlibra.transaction.SignedTransaction)

Aggregations

DiemClient (dev.jlibra.client.DiemClient)14 AuthenticationKey (dev.jlibra.AuthenticationKey)6 AccountAddress (dev.jlibra.AccountAddress)5 Faucet (dev.jlibra.faucet.Faucet)5 Account (dev.jlibra.client.views.Account)4 PublicKey (dev.jlibra.PublicKey)3 Transaction (dev.jlibra.client.views.transaction.Transaction)3 ImmutableSignedTransaction (dev.jlibra.transaction.ImmutableSignedTransaction)3 ImmutableTransaction (dev.jlibra.transaction.ImmutableTransaction)3 SignedTransaction (dev.jlibra.transaction.SignedTransaction)3 Transaction (dev.jlibra.transaction.Transaction)3 AccountAddressArgument (dev.jlibra.transaction.argument.AccountAddressArgument)3 U64Argument (dev.jlibra.transaction.argument.U64Argument)3 U8VectorArgument (dev.jlibra.transaction.argument.U8VectorArgument)3 KeyPair (java.security.KeyPair)3 KeyPairGenerator (java.security.KeyPairGenerator)2 PrivateKey (java.security.PrivateKey)2 DiemRuntimeException (dev.jlibra.DiemRuntimeException)1 MultiSignaturePublicKey (dev.jlibra.MultiSignaturePublicKey)1 BatchRequest (dev.jlibra.client.jsonrpc.BatchRequest)1