diff --git a/build.gradle b/build.gradle index 5f8c5e3..4d0b90e 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,20 @@ sourceCompatibility = 1.8 def grpc_java_version = '1.14.0' +tasks.withType(JavaCompile) { + options.encoding = "UTF-8" +} + +javadoc { + source = sourceSets.main.allJava + classpath = configurations.compile + options { + encoding 'UTF-8' + charSet 'UTF-8' + title "BDChain Java SDK API" + } +} + protobuf { protoc { artifact = "com.google.protobuf:protoc:3.6.0" diff --git a/src/main/java/bdchain/api/AccountingChainClient.java b/src/main/java/bdchain/api/AccountingChainClient.java index 124b6e1..b146b4c 100644 --- a/src/main/java/bdchain/api/AccountingChainClient.java +++ b/src/main/java/bdchain/api/AccountingChainClient.java @@ -15,6 +15,14 @@ import java.util.logging.Logger; // import bdchain.api.grpc.AccountingChainGrpc.AccountingChainStub; +/** + * 记账链客户端 + * + *

如有更灵活的需求可直接使用{@link bdchain.api.grpc.AccountingChainGrpc}类。 + * + * @see 记账链API + * @author nex + */ public class AccountingChainClient { private static final Logger logger = Logger.getLogger(AccountingChainClient.class.getName()); @@ -22,26 +30,32 @@ public class AccountingChainClient { private final ManagedChannel channel; private final AccountingChainFutureStub futureStub; private final AccountingChainBlockingStub blockingStub; - // private final AccountingChainStub asyncStub; +// private final AccountingChainStub asyncStub; - /** Construct client for accessing AccountingChain server at {@code host:port}. */ + /** 构造客户端来访问{@code host:port}的记账链服务。 */ public AccountingChainClient(String host, int port) { this(ManagedChannelBuilder.forAddress(host, port).usePlaintext()); } - /** Construct client for accessing AccountingChain server using the existing channel. */ + /** 用已有的{@link io.grpc.Channel}对象构造客户端来访问记账链服务。 */ public AccountingChainClient(ManagedChannelBuilder channelBuilder) { channel = channelBuilder.build(); AccountingChainGrpc.newFutureStub(channel); futureStub = AccountingChainGrpc.newFutureStub(channel); blockingStub = AccountingChainGrpc.newBlockingStub(channel); - // asyncStub = AccountingChainGrpc.newStub(channel); +// asyncStub = AccountingChainGrpc.newStub(channel); } + /** 关闭客户端的网络连接。 */ public void shutdown() throws InterruptedException { channel.shutdown().awaitTermination(5, TimeUnit.SECONDS); } + /** + * 返回最新区块的区块号 + * (非阻塞) + */ public ListenableFuture blockNumber(String ledger) { info("*** blockNumber: ledger={0}", ledger); @@ -56,6 +70,11 @@ public class AccountingChainClient { } } + /** + * 返回最新区块的区块号 + * (阻塞) + */ public BlockNumberResponse blockNumberSync(String ledger) { info("*** blockNumberSync: ledger={0}", ledger); @@ -70,6 +89,11 @@ public class AccountingChainClient { } } + /** + * 返回区块号所指定区块的信息 + * (非阻塞) + */ public ListenableFuture getBlockByNumber( String ledger, long number, boolean fullTransaction) { @@ -92,6 +116,11 @@ public class AccountingChainClient { } } + /** + * 返回区块号所指定区块的信息 + * (阻塞) + */ public Block getBlockByNumberSync(String ledger, long number, boolean fullTransaction) { info( @@ -113,6 +142,11 @@ public class AccountingChainClient { } } + /** + * 返回哈希所指定区块的信息 + * (非阻塞) + */ public ListenableFuture getBlockByHash( String ledger, String hash, boolean fullTransaction) { @@ -135,6 +169,11 @@ public class AccountingChainClient { } } + /** + * 返回哈希所指定区块的信息 + * (阻塞) + */ public Block getBlockByHashSync(String ledger, String hash, boolean fullTransaction) { info( @@ -156,6 +195,11 @@ public class AccountingChainClient { } } + /** + * 返回哈希所指定事务的信息 + * (非阻塞) + */ public ListenableFuture getTransactionByHash(String ledger, String hash) { info("*** getTransactionByHash: ledger={0} hash={1}", ledger, hash); @@ -174,6 +218,11 @@ public class AccountingChainClient { } } + /** + * 返回哈希所指定事务的信息 + * (阻塞) + */ public Transaction getTransactionByHashSync(String ledger, String hash) { info("*** getTransactionByHashSync: ledger={0} hash={1}", ledger, hash); @@ -192,6 +241,11 @@ public class AccountingChainClient { } } + /** + * 返回区块号与事务index所指定事务的信息 + * (非阻塞) + */ public ListenableFuture getTransactionByBlockNumberAndIndex( String ledger, long block_number, int index) { @@ -214,6 +268,11 @@ public class AccountingChainClient { } } + /** + * 返回区块号与事务index所指定事务的信息 + * (阻塞) + */ public Transaction getTransactionByBlockNumberAndIndexSync( String ledger, long block_number, int index) { @@ -236,6 +295,11 @@ public class AccountingChainClient { } } + /** + * 返回区块的哈希与事务的index所指定事务的信息 + * (非阻塞) + */ public ListenableFuture getTransactionByBlockHashAndIndex( String ledger, String block_hash, int index) { @@ -258,6 +322,11 @@ public class AccountingChainClient { } } + /** + * 返回区块的哈希与事务的index所指定事务的信息 + * (阻塞) + */ public Transaction getTransactionByBlockHashAndIndexSync( String ledger, String block_hash, int index) { diff --git a/src/main/java/bdchain/api/TransactionLedgerClient.java b/src/main/java/bdchain/api/TransactionLedgerClient.java index a66cae5..421baa2 100644 --- a/src/main/java/bdchain/api/TransactionLedgerClient.java +++ b/src/main/java/bdchain/api/TransactionLedgerClient.java @@ -16,6 +16,14 @@ import java.util.logging.Logger; // import bdchain.api.grpc.TransactionLedgerGrpc.TransactionLedgerStub; +/** + * 事务账本客户端 + * + *

如有更灵活的需求可直接使用{@link bdchain.api.grpc.TransactionLedgerGrpc}类。 + * + * @see 事务账本API + * @author nex + */ public class TransactionLedgerClient { private static final Logger logger = Logger.getLogger(TransactionLedgerClient.class.getName()); @@ -25,12 +33,12 @@ public class TransactionLedgerClient { private final TransactionLedgerBlockingStub blockingStub; // private final TransactionLedgerStub asyncStub; - /** Construct client for accessing TransactionLedger server at {@code host:port}. */ + /** 构造客户端来访问{@code host:port}的事务账本服务。 */ public TransactionLedgerClient(String host, int port) { this(ManagedChannelBuilder.forAddress(host, port).usePlaintext()); } - /** Construct client for accessing TransactionLedger server using the existing channel. */ + /** 用已有的{@link io.grpc.Channel}对象构造客户端来访问事务账本服务。 */ public TransactionLedgerClient(ManagedChannelBuilder channelBuilder) { channel = channelBuilder.build(); futureStub = TransactionLedgerGrpc.newFutureStub(channel); @@ -38,10 +46,15 @@ public class TransactionLedgerClient { // asyncStub = TransactionLedgerGrpc.newStub(channel); } + /** 关闭客户端的网络连接。 */ public void shutdown() throws InterruptedException { channel.shutdown().awaitTermination(5, TimeUnit.SECONDS); } + /** + * 创建账本 + * (非阻塞) + */ public ListenableFuture createLedger(String name) { info("*** createLedger: name={0}", name); @@ -56,6 +69,10 @@ public class TransactionLedgerClient { } } + /** + * 创建账本 + * (阻塞) + */ public CreateLedgerResponse createLedgerSync(String name) { info("*** createLedgerSync: name={0}", name); @@ -70,6 +87,10 @@ public class TransactionLedgerClient { } } + /** + * 返回账本列表 + * (非阻塞) + */ public ListenableFuture getLedgers() { info("*** getLedgers"); @@ -82,6 +103,10 @@ public class TransactionLedgerClient { } } + /** + * 返回账本列表 + * (阻塞) + */ public GetLedgersResponse getLedgersSync() { info("*** getLedgersSync"); @@ -94,6 +119,11 @@ public class TransactionLedgerClient { } } + /** + * 发送新事务 + * (非阻塞) + */ public ListenableFuture sendTransaction( String ledger, TransactionType type, String from, String to, byte[] data) { @@ -120,6 +150,11 @@ public class TransactionLedgerClient { } } + /** + * 发送新事务 + * (阻塞) + */ public SendTransactionResponse sendTransactionSync( String ledger, TransactionType type, String from, String to, byte[] data) {