エンベロープ トランザクションは、プライバシー保護のために独立したグループで実行されます。スマート コントラクト プラットフォームは、コントラクトのデプロイ、呼び出し、更新、およびクエリのためのエンベロープ トランザクションをサポートしています。
depositEnvelope
この API は、エンベロープ トランザクションに対して同期的に呼び出されます。
関数プロトタイプ
public DepositEnvelopeResponse depositEnvelope(DepositEnvelopeRequest request)
リクエスト パラメーター
パラメーター | 必須 | 型 | 説明 |
request | true |
| エンベロープ トランザクション リクエスト。 |
DepositEnvelopeRequest パラメーター。
パラメーター | 必須 | 型 | 説明 |
anoymousIdentity | true | Identity | 匿名 ID。 |
signerBases | true |
| 署名構成オプション。 |
keypair | true | Keypair | キーペア。 |
GroupTransactionRequest
は DepositEnvelopeRequest
の親クラスです。
パラメーター | 型 | 説明 |
request |
| 内部トランザクション。コントラクトのデプロイ、コントラクトの呼び出し、コントラクトの更新などを含みます。 |
レスポンス フィールド
レスポンス フィールド | フィールド型 | 説明 |
response |
| エンベロープ トランザクション レスポンス。 |
DepositEnvelopeResponse パラメーター。
パラメーター | 型 | 説明 |
transactionReceipt |
| トランザクション レシート。 |
blockNumber | BigInteger | ブロック番号。 |
txIndex | int | トランザクション オフセット |
txHash | Hash | トランザクション ハッシュ |
isLocalTransaction | boolean | トランザクションがローカル トランザクションかどうか |
TransactionReceipt パラメーター。
パラメーター | 型 | 説明 |
result | long | トランザクション実行結果: 0 は成功を表し、その他の値は失敗を示します。 |
gasUsed | BigInteger | トランザクションで発生したガス料金。 |
logs |
| トランザクション結果のログ出力。 |
output | byte[] | トランザクションの出力。このコンテキストでは、仮想マシンの実行結果です。 |
LogEntry パラメーター。
パラメーター | 型 | 説明 |
from | Identity | トランザクション結果ログ内の、トランザクション送信元を表すフィールド。 |
to | Identity | トランザクション結果ログ内の、トランザクション受信者を表すフィールド。 |
topics | List<String> | トランザクション結果ログ内の、トランザクション実行のイベント トピックを表すフィールド。 |
logData | byte[] | トランザクション結果ログ内の、トランザクション実行のログ データを表すフィールド。 |
例
public void depositEnvelope() {
// グループを作成する
CreateGroupRequest createGroupRequest = new CreateGroupRequest(new PublicKey(keypair.getPubkeyId()), Utils.getIdentityByName("Administrator"));
createGroupResponse = sdk.getEnvelopeService().createGroup(createGroupRequest);
// グループに参加する
byte[] groupPrivateKey = createGroupResponse.getPrivateKey();
PublicKey anoymousPublicKey = new PublicKey(keypair.getPubkeyId());
JoinGroupRequest joinGroupRequest = new JoinGroupRequest(groupPrivateKey, anoymousPublicKey, createGroupResponse.getGroupId(), Utils.getIdentityByName("Administrator"));
JoinGroupResponse joinGroupResponse = sdk.getEnvelopeService().joinGroup(joinGroupRequest);
// createGroupResponse から groupId を取得する
BaseFixedSizeByteArray.Fixed20ByteArray groupId = createGroupResponse.getGroupId();
// createGroupResponse から keypair を取得する
Pkcs8KeyOperator pkcs8KeyOperator = new Pkcs8KeyOperator();
Keypair keypair = pkcs8KeyOperator.loadFromPrivkey(createGroupResponse.getPrivateKey());
// keypair から signerOption を作成する
SignerOption signerOption = new SignerOption();
List<SignerBase> signerBases = new ArrayList<>();
signerBases.add(MyCrypto.getInstance().createSigner(keypair));
signerOption.setSigners(signerBases);
// 内部リクエストを作成する
// アカウントを構築する
String accountName = "accountName";
Identity userIdentity = Utils.getIdentityByName(accountName);
Account account = new Account();
account.setIdentity(userIdentity);
account.setBalance(BigInteger.ZERO);
account.setStatus(AccountStatus.NORMAL);
AuthMap authMap = new AuthMap();
account.setAuthMap(authMap.updateAuth(new PublicKey(administratorPublicKey1), 100));
account.setAuthMap(authMap.updateAuth(new PublicKey(administratorPublicKey2), 100));
account.setAuthMap(authMap.updateAuth(new PublicKey(administratorPublicKey3), 100));
account.setAuthMap(authMap.updateAuth(new PublicKey(administratorPublicKey4), 100));
account.setRecoverKey(new PublicKey(administratorPublicKey1));
CreateAccountRequest createAccountRequest = new CreateAccountRequest(Utils.getIdentityByName("Administrator"), account);
// DepositEnvelopeRequest を作成する
IHash hashTool = HashFactory.getHash();
DepositEnvelopeRequest request = new DepositEnvelopeRequest(createAccountRequest, groupId, signerBases, keypair);
request.setAnonymousIdentity(new Identity(hashTool.hash(keypair.getPubkeyId())));
DepositEnvelopeResponse depositEnvelopeResponse = sdk.getEnvelopeService().depositEnvelope(request);
if (!depositEnvelopeResponse.isSuccess()) {
logger.error("depositEnvelope 失敗、エラーコード :{}, エラー内容: {}", depositEnvelopeResponse.getErrorCode().getErrorCode(), depositEnvelopeResponse.getErrorCode().getErrorDesc());
} else {
// トランザクション レシート
TransactionReceipt transactionReceipt = depositEnvelopeResponse.getTransactionReceipt();
if (transactionReceipt.getResult() != 0) {
logger.error("depositEnvelope 失敗、エラーコード :{}, エラー内容: {}", ErrorCode.valueOf((int) transactionReceipt.getResult()).getErrorCode(), ErrorCode.valueOf((int) transactionReceipt.getResult()).getErrorDesc());
} else {
logger.info("depositEnvelope 成功。戻り情報: {}", transactionReceipt.toString());
}
}
}
asyncDepositRequest
この API は、エンベロープ トランザクションに対して非同期的に呼び出されます。
関数プロトタイプ
public int asyncDepositRequest(DepositEnvelopeRequest request, IAsyncCallback callback)
リクエスト パラメーター
パラメーター | 必須 | 型 | 説明 |
request | true |
| エンベロープ トランザクション リクエスト。 |
callback | true | IAsyncCallback | コールバック関数。 |
DepositEnvelopeRequest パラメーター。
パラメーター | 必須 | 型 | 説明 |
anoymousIdentity | true | Identity | 匿名 ID。 |
signerBases | true |
| 署名構成オプション。 |
keypair | true | Keypair | キーペア。 |
GroupTransactionRequest
は DepositEnvelopeRequest
の親クラスです。
パラメーター | 型 | 説明 |
request |
| 内部トランザクション。コントラクトのデプロイ、コントラクトの呼び出し、コントラクトの更新などを含みます。 |
レスポンス フィールド
レスポンス フィールド | フィールド型 | 説明 |
result | int | 戻り値。 |
非同期 応答フィールド
レスポンス フィールド | フィールド型 | 説明 |
errorCode | int | SDK がメッセージ タイムアウトを送信したか、または正常に送信されたか。 |
response |
| プラットフォームから返されたレスポンス。 |
(DepositEnvelopeResponse)Response
レスポンス フィールド | フィールド型 | 説明 |
transactionReceipt |
| トランザクション レシート。 |
blockNumber | BigInteger | ブロック番号。 |
txIndex | int | トランザクション オフセット |
txHash | Hash | トランザクション ハッシュ |
isLocalTransaction | boolean | トランザクションがローカル トランザクションかどうか |
TransactionReceipt パラメーター。
パラメーター | 型 | 説明 |
result | long | トランザクション実行結果: 0 は成功を表し、その他の値は失敗を示します。 |
gasUsed | BigInteger | トランザクションで発生したガス料金。 |
logs |
| トランザクション結果のログ出力。 |
output | byte[] | トランザクションの出力。このコンテキストでは、仮想マシンの実行結果です。 |
LogEntry パラメーター。
パラメーター | 型 | 説明 |
from | Identity | トランザクション結果ログ内の、トランザクション送信元を表すフィールド。 |
to | Identity | トランザクション結果ログ内の、トランザクション受信者を表すフィールド。 |
topics | List<String> | トランザクション結果ログ内の、トランザクション実行のイベント トピックを表すフィールド。 |
logData | byte[] | トランザクション結果ログ内の、トランザクション実行のログ データを表すフィールド。 |
例
DepositEnvelopeRequest request = new DepositEnvelopeRequest(createAccountRequest, groupId, signerBases, keypair);
request.setAnoymousIdentity(new Identity(hashTool.hash(keypair.getPubkeyId())));
int result = sdk.getEnvelopeService().asyncDepositRequest(
request,
new IAsyncCallback() {
@Override
public void onResponse(int errorCode, Response response) {
// エラーコードに関するトピックを参照して、返されたデータを確認してください。
System.out.println("非同期 deposit envelope、エラーコード:" + errorCode + ", レスポンス: " + response.getErrorCode());
DepositEnvelopeResponse receiptResponse = (DepositEnvelopeResponse) response;
}
});