账本操作API

API 描述
statLedger 查询账本当前状态及相关统计数据

成员操作API

API 描述
updateMemberKey 更新账本成员公钥
deleteMember 删除成员
getMember 查询账本成员
listMembers 批量查询账本成员
enableMember 激活账本成员
disableMember 禁用账本成员

记录(数据)操作API

API 描述
appendTransaction 新增记录
getTransaction 读取记录
existTransaction 查询记录是否存在
listTransactions 批量获取历史记录
getBlockInfo 获取区块信息
listTimeAnchors 批量查询可信时间戳
getLastTimeAnchor 查询最新的可信时间戳
getProof 获取记录证明

秘钥生成

API 描述
ECCK1KeyPair 秘钥对生成 秘钥对类,包含构造器和静态生成秘钥方法

API详细描述

账本操作API

statLedger

方法定义

public StatLedgerResponse statLedger(String ledgerUri,OperationControl opControl)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.common.StatLedgerResponse;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class StatLedgerDemo {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    StatLedgerResponse response = client.statLedger(ledgerUri, op);
  }
}

成员操作API

createMember

方法定义

public CreateMemberResponse createMember(String ledgerUri, MemberInfo memberInfo, OperationControl operationControl)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.CreateMemberResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.MemberInfo;
import com.antfin.ledgerdb.client.proto.Sender;
import com.google.protobuf.ByteString;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class CreateMemberDemo {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    String providedPublicKeyInHex = "provided public key in hex";
    ByteString publicKeyInByteString = ByteString.copyFrom(Hex.decode(providedPublicKeyInHex));
    CreateMemberResponse response = 
        client.createMember(ledgerUri, MemberInfo.newBuilder().setPublicKey(publicKeyInByteString).build(), op);
  }
}

updateMember

方法定义

public UpdateMemberResponse updateMember(
      String ledgerUri,
      MemberInfo memberInfo,
      OperationControl operationControl)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.common.UpdateMemberResponse;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.MemberInfo;
import com.antfin.ledgerdb.client.proto.Sender;
import com.google.protobuf.ByteString;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class UpdateMemberDemo {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    byte[] newPublicKey = Hex.decode("new public key in hex");
    MemberInfo memberInfo =
        MemberInfo.newBuilder()
            .setMemberId(memberId)
            .setPublicKey(ByteString.copyFrom(newPublicKey))
            .build();
    UpdateMemberResponse response = client.updateMember(ledgerUri, memberInfo, op);

  }
}

updateMemberKey

方法定义

public UpdateMemberKeyResponse updateMemberKey(
          String ledgerUri,
          String memberId,
          ByteString publicKey,
          OperationControl operationControl)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.common.UpdateMemberKeyResponse;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import com.google.protobuf.ByteString;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class UpdateMemberKeyDemo {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    byte[] newPublicKey = Hex.decode("new public key in hex");
    UpdateMemberKeyResponse response = client.updateMemberKey(ledgerUri, memberId, ByteString.copyFrom(newPublicKey), op);
  }
}

deleteMember

方法定义

public DeleteMemberResponse deleteMember(
      String ledgerUri,
      String memberId,
      OperationControl opControl)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.DeleteMemberResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class DeleteMemberDemo {


  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    String memberToBeDeleted = "*****";
    DeleteMemberResponse response = client.deleteMember(ledgerUri, memberToBeDeleted, op);
    
  }
}

getMember

方法定义

public GetMemberResponse getMember(
      String ledgerUri,
      String memberId,
      OperationControl operationControl)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.GetMemberResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class GetMemberDemo {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    GetMemberResponse response = client.getMember(ledgerUri, memberId, op);
  }
}

listMembers

方法定义

public ListMembersResponse listMembers(
          String ledgerUri,
          String lastMemberId,
          int limit,
          OperationControl operationControl)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.ListMembersResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class ListMembers {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    ListMembersResponse response = client.listMembers(ledgerUri, "", 20, op);
  }

enableMember

方法定义

public EnableMemberResponse enableMember(
      String ledgerUri,
      String memberId,
      OperationControl op)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.EnableMemberResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class EnableMemberDemo {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    String memberToEnable = "*****";
    EnableMemberResponse enableMemberResponse = client.enableMember(ledgerUri, memberToEnable, op);

  }
}

disableMember

方法定义

public DisableMemberResponse disableMember(
      String ledgerUri,
      String memberId,
      OperationControl op)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.DisableMemberResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class DisableMemberDemo {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    String memberToDisable = "*****";
    DisableMemberResponse disableMemberResponse = client.disableMember(ledgerUri, memberToDisable, op);
  }
}

记录(数据)操作API

appendTransaction

方法定义

public AppendTransactionResponse appendTransaction(
      String ledgerUri,
      byte[] data,
      OperationControl opControl)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.AppendTransactionResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

import java.nio.charset.StandardCharsets;

public class AppendTransactionDemo {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    AppendTransactionResponse response =
        client.appendTransaction(ledgerUri, "Hello world".getBytes(StandardCharsets.UTF_8), op);

  }
}

getTransaction

方法定义

public GetTransactionResponse getTransaction(
      String ledgerUri,
      long txSequence,
      OperationControl opControl)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.GetTransactionResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class GetTransaction {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    GetTransactionResponse response = client.getTransaction(ledgerUri, 10, op);
  }
}

existTransaction

方法定义

public ExistTransactionResponse existTransaction(
      String ledgerUri,
      long txSequence,
      OperationControl opControl)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.ExistTransactionResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class ExistTransactionDemo {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    ExistTransactionResponse response = client.existTransaction(ledgerUri, 10, op);
  }
}

listTransactions

方法定义

public ListTransactionsResponse listTransactions(
      String ledgerUri,
      String clue,
      long beginSequence,
      int limit,
      OperationControl opControl)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.ListTransactionsResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class ListTransactionsDemo {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    ListTransactionsResponse response =
        client.listTransactions(ledgerUri, "", 1, 10, op);
  }
}

setTrustPoint

方法定义

public SetTrustPointResponse setTrustPoint(
      String ledgerUri,
      long sequence,
      OperationControl op)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.SetTrustPointResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class SetTrustPointDemo {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    SetTrustPointResponse response = client.setTrustPoint(ledgerUri, 10, op);
  }
}

getTrustPoint

方法定义

public GetTrustPointResponse getTrustPoint(
      String ledgerUri,
      OperationControl op)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.GetTrustPointResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class GetTrustPoint {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    GetTrustPointResponse getTrustPointResponse = client.getTrustPoint(ledgerUri, op);
  }
}

getLastTimeAnchor

方法定义

public GetTrustPointResponse getTrustPoint(
      String ledgerUri,
      OperationControl op)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.GetLastTimeAnchorResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class GetLastTimeAnchorDemo {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    GetLastTimeAnchorResponse response = client.getLastTimeAnchor(ledgerUri, op);
  }
}

listTimeAnchors

方法定义

public ListTimeAnchorsResponse listTimeAnchors(
      String ledgerUri,
      long startSequence,
      int limit,
      boolean reverse,
      OperationControl op)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.ListTimeAnchorsResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class ListTimeAnchorsDemo {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    ListTimeAnchorsResponse response =
        client.listTimeAnchors(ledgerUri, 10, 10, false, op);
  }
}

getBlockInfo

方法定义

public GetBlockInfoResponse getBlockInfo(
      String ledgerUri,
      long blockSequence,
      OperationControl op)

示例

import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.GetBlockInfoResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;

public class GetBlockInfoDemo {

  String ledgerId = "*****";

  String memberId = "*****";

  String privateKeyInHex = "your private key in hex";

  String publicKeyInHex = "your public key in hex";

  byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);

  byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);

  String ledgerHost = "127.0.0.1";

  Integer ledgerPort = 10099;

  LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);
  SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);

  @Test
  public void test() {
    OperationControl op = new OperationControl();
    op.addSignerProfile(
        new SignerProfile(
            memberId,
            Sender.SenderType.REGULAR,
            signerKeyPair));
    String ledgerUri = "ledger://127.0.0.1:10099/*****";
    GetBlockInfoResponse response = client.getBlockInfo(ledgerUri, 5, op);
  }
}

getProof

方法定义

public GetProofResponse getProof(String ledgerUri, long txSequence, OperationControl op)
示例
import com.antfin.ledgerdb.client.LedgerDBLightClient;
import com.antfin.ledgerdb.client.OperationControl;
import com.antfin.ledgerdb.client.common.GetBlockInfoResponse;
import com.antfin.ledgerdb.client.common.GetProofResponse;
import com.antfin.ledgerdb.client.common.SignerProfile;
import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair;
import com.antfin.ledgerdb.client.crypto.SignerKeyPair;
import com.antfin.ledgerdb.client.proto.Sender;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;
public class GetProofDemo {  
    String ledgerId = "*****";  
    String memberId = "*****";  
    String privateKeyInHex = "your private key in hex";  
    String publicKeyInHex = "your public key in hex"; 
    
    byte[] privateKeyInBytes = Hex.decode(privateKeyInHex);  
    byte[] publicKeyInBytes = Hex.decode(publicKeyInHex);  
    String ledgerHost = "127.0.0.1";  
    Integer ledgerPort = 10099;  
    LedgerDBLightClient client = new LedgerDBLightClient(ledgerHost, ledgerPort);  
    SignerKeyPair signerKeyPair = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);  
    @Test
    public void test() {    
        OperationControl op = new OperationControl();    
        op.addSignerProfile(new SignerProfile( memberId,  Sender.SenderType.REGULAR, signerKeyPair));
        String ledgerUri = "ledger://127.0.0.1:10099/*****";
        GetProofResponse response = client.getProof(ledgerUri, 5, op);
    }
}

ECCK1KeyPair 秘钥对生成

import com.antfin.ledgerdb.client.crypto.ECCK1KeyPair; 
import com.antfin.ledgerdb.client.crypto.Keys;
import org.bouncycastle.util.encoders.Hex;
import org.junit.Test;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
public class KeyGenTest {  
    @Test
    public void testGen() throws 
           InvalidAlgorithmParameterException, 
           NoSuchAlgorithmException, 
           NoSuchProviderException {    
      
      ECCK1KeyPair key = Keys.createEcKeyPair();    
     // 64 bytes    
     byte[] publicKeyInBytes = key.getPublicKey();    
     // 32 bytes    
     byte[] privateKeyInBytes = key.getPrivateKey();                                   
     System.out.println(Hex.toHexString(publicKeyInBytes));        
     System.out.print(Hex.toHexString(privateKeyInBytes));  
   }
   @Test
   public void testConstructors() throws 
          InvalidAlgorithmParameterException, 
          NoSuchAlgorithmException, 
          NoSuchProviderException {  
      
     ECCK1KeyPair key = Keys.createEcKeyPair(); 
     // 64 bytes  
     byte[] publicKeyInBytes = key.getPublicKey();
     // 32 bytes  
     byte[] privateKeyInBytes = key.getPrivateKey();  
     // construct from private key in bytes 
     ECCK1KeyPair keyConstructed = new ECCK1KeyPair(privateKeyInBytes);  
     // construct from private key in bytes and public key in bytes  
     // public key should be 64 bytes  
     ECCK1KeyPair keyConstructed2 = new ECCK1KeyPair(privateKeyInBytes, publicKeyInBytes);}
}