forked from diem/client-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntentId.java
36 lines (29 loc) · 1.3 KB
/
IntentId.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) The Libra Core Contributors
// SPDX-License-Identifier: Apache-2.0
package org.libra.examples;
import org.junit.Assert;
import org.junit.Test;
import org.libra.AccountIdentifier;
import org.libra.IntentIdentifier;
import org.libra.LocalAccount;
import org.libra.Testnet;
import org.libra.utils.CurrencyCode;
public class IntentId {
@Test
public void encodeAndDecode() {
LocalAccount merchant = LocalAccount.generate();
long amount = 5_000_000;
AccountIdentifier merchantAccountId = new AccountIdentifier(
AccountIdentifier.NetworkPrefix.TestnetPrefix,
merchant.address
);
IntentIdentifier intentId = new IntentIdentifier(merchantAccountId, Testnet.COIN1, amount);
String encodeIntent = intentId.encode();
System.out.println("encoded intent identifier: " + encodeIntent);
// payer receives encode intent, decode for creating payment transaction
IntentIdentifier decodedIntent = IntentIdentifier.decode(AccountIdentifier.NetworkPrefix.TestnetPrefix, encodeIntent);
Assert.assertEquals(merchantAccountId, decodedIntent.getAccountIdentifier());
Assert.assertEquals(Testnet.COIN1, decodedIntent.getCurrency());
Assert.assertEquals(amount, decodedIntent.getAmount());
}
}