3 import com.google.gson.annotations.SerializedName;
4 import io.bytom.common.Utils;
5 import io.bytom.exception.BytomException;
6 import io.bytom.http.Client;
7 import org.apache.log4j.Logger;
9 import java.util.HashMap;
10 import java.util.List;
14 * <h1>Wallet Class</h1>
18 @SerializedName("account_image")
19 public AccountImage accountImage;
21 @SerializedName("asset_image")
22 public AssetImage assetImage;
24 @SerializedName("key_images")
25 public KeyImages keyImages;
27 private static Logger logger = Logger.getLogger(Wallet.class);
30 * Serializes the Address into a form that is safe to transfer over the wire.
32 * @return the JSON-serialized representation of the Receiver object
34 public String toJson() {
35 return Utils.serializer.toJson(this);
39 * Call backup-wallet api
43 * @throws BytomException
45 public static Wallet backupWallet(Client client) throws BytomException {
46 Wallet wallet = client.request("backup-wallet", null, Wallet.class);
48 logger.info("backup-wallet:");
49 logger.info(wallet.toJson());
55 * Call restore-wallet api
61 * @throws BytomException
63 public static void restoreWallet(Client client ,Object accountImage, Object assetImage , Object keyImages) throws BytomException{
64 Map<String, Object> body = new HashMap<String, Object>();
65 body.put("account_image", accountImage);
66 body.put("asset_image", assetImage);
67 body.put("key_images", keyImages);
69 logger.info("restore-wallet:");
70 logger.info(body.toString());
72 client.request("restore-wallet", body);
75 public static class AccountImage {
77 public Slices[] slices;
79 public static class Slices {
81 @SerializedName("contract_index")
82 public int contractIndex;
84 public Account account;
86 public static class Account {
90 public List<String> xpubs;
94 @SerializedName("key_index")
106 public static class AssetImage {
108 public Assets[] assets;
110 public static class Assets {
112 public List<String> xpubs;
116 public Map<String, Object> definition;
117 @SerializedName("key_index")
119 @SerializedName("vm_version")
120 public int vmVersion;
121 @SerializedName("asset_image")
122 public String issueProgram;
123 @SerializedName("raw_definition_byte")
124 public String rawDefinitionByte;
128 public static class KeyImages {
130 public Xkeys[] xkeys;
132 public static class Xkeys {
134 public Crypto crypto;
141 public static class Crypto {
142 public String cipher;
143 public String ciphertext;
144 public Map<String, Object> cipherparams;
146 public Map<String, Object> kdfparams;