web3j除了实现最基本的标准JSON-RPC API
,以太坊客户端,如Geth
和Parity
,通过JSON-RPC
提供额外的管理API。
它们提供的一个关键的通用功能是创建和解锁在网络上交易的以太坊帐户的能力。在Geth和Parity中,这是在它们的私有模块中实现的,其中的细节可在下面得到:
在web3j中对这些私有模块的提供支持。这些方法对于Geth
和Parity
都是通用的,它存在于web3j的管理模块Admin
中。
1 | package org.web3j.protocol.admin; |
可以初始化一个新的web3j连接器,使用Admin
模块的工厂方法:
1 | Admin web3j = Admin.build(new HttpService()); // defaults to http://localhost:8545/ |
对于geth
特定方法,可以使用geth连接器:
1 | package org.web3j.protocol.geth; |
而对于Parity,则可以使用相关的Parity 连接器。Parity连接器还提供对Parity的Trace模块的支持。这些连接器分别在web3j的geth
和parity
模块中可用。
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91package org.web3j.protocol.parity;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.web3j.crypto.WalletFile;
import org.web3j.protocol.Web3jService;
import org.web3j.protocol.admin.Admin;
import org.web3j.protocol.admin.methods.response.BooleanResponse;
import org.web3j.protocol.admin.methods.response.NewAccountIdentifier;
import org.web3j.protocol.admin.methods.response.PersonalSign;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.Request;
import org.web3j.protocol.parity.methods.request.Derivation;
import org.web3j.protocol.parity.methods.response.ParityAddressesResponse;
import org.web3j.protocol.parity.methods.response.ParityAllAccountsInfo;
import org.web3j.protocol.parity.methods.response.ParityDefaultAddressResponse;
import org.web3j.protocol.parity.methods.response.ParityDeriveAddress;
import org.web3j.protocol.parity.methods.response.ParityExportAccount;
import org.web3j.protocol.parity.methods.response.ParityListRecentDapps;
/**
* JSON-RPC Request object building factory for Parity.
*/
public interface Parity extends Admin, Trace {
static Parity build(Web3jService web3jService) {
return new JsonRpc2_0Parity(web3jService);
}
Request<?, ParityAllAccountsInfo> parityAllAccountsInfo();
Request<?, BooleanResponse> parityChangePassword(
String accountId, String oldPassword, String newPassword);
Request<?, ParityDeriveAddress> parityDeriveAddressHash(
String accountId, String password, Derivation hashType, boolean toSave);
Request<?, ParityDeriveAddress> parityDeriveAddressIndex(
String accountId, String password, List<Derivation> indicesType, boolean toSave);
Request<?, ParityExportAccount> parityExportAccount(String accountId, String password);
Request<?, ParityAddressesResponse> parityGetDappAddresses(String dAppId);
Request<?, ParityDefaultAddressResponse> parityGetDappDefaultAddress(String dAppId);
Request<?, ParityAddressesResponse> parityGetNewDappsAddresses();
Request<?, ParityDefaultAddressResponse> parityGetNewDappsDefaultAddress();
Request<?, ParityAddressesResponse> parityImportGethAccounts(ArrayList<String> gethAddresses);
Request<?, BooleanResponse> parityKillAccount(String accountId, String password);
Request<?, ParityAddressesResponse> parityListAccounts(
BigInteger quantity, String accountId, DefaultBlockParameter blockParameter);
Request<?, ParityAddressesResponse> parityListGethAccounts();
Request<?, ParityListRecentDapps> parityListRecentDapps();
Request<?, NewAccountIdentifier> parityNewAccountFromPhrase(String phrase, String password);
Request<?, NewAccountIdentifier> parityNewAccountFromSecret(String secret, String password);
Request<?, NewAccountIdentifier> parityNewAccountFromWallet(
WalletFile walletFile, String password);
Request<?, BooleanResponse> parityRemoveAddress(String accountId);
Request<?, BooleanResponse> paritySetAccountMeta(
String accountId, Map<String, Object> metadata);
Request<?, BooleanResponse> paritySetAccountName(String address, String name);
Request<?, BooleanResponse> paritySetDappAddresses(
String dAppId, ArrayList<String> availableAccountIds);
Request<?, BooleanResponse> paritySetDappDefaultAddress(String dAppId, String defaultAddress);
Request<?, BooleanResponse> paritySetNewDappsAddresses(ArrayList<String> availableAccountIds);
Request<?, BooleanResponse> paritySetNewDappsDefaultAddress(String defaultAddress);
Request<?, BooleanResponse> parityTestPassword(String accountId, String password);
Request<?, PersonalSign> paritySignMessage(
String accountId, String password, String hexMessage);
}
你可以参考集成测试ParityIT,了解使用这些API的例子。
1 | package org.web3j.protocol.parity; |
汇智网原创翻译,转载请标明出处。这里是原文