fabric-java-sdk ——建立简单的请求(脱离配置)

本文档介绍了如何使用fabric-java-sdk建立简单的请求,通过修改UserInfo和Enrollment类,简化了参数设置。测试在本地dev环境中进行,启用TLS时可调整验证选项。
摘要由CSDN通过智能技术生成

前言

一如既往的,直接通过参数进行对fabric节点的调用。

重写一个UserInfo和Enrollment

//改为直接传入string的key.

public class FCUserInfo implements User {
    protected String name;
    protected String mspid;
    private Set<String> roles;
    private String account;
    private String affiliation;
    private Enrollment enrollment;

    public FCUserInfo(String mspid, String pem, String key) {
        this.name=UUID.randomUUID().toString();
        this.mspid = mspid;
        this.enrollment = new FCEnrollment(pem, key);
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setMspid(String mspid) {
        this.mspid = mspid;
    }

    public void setRoles(Set<String> roles) {
        this.roles = roles;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public void setAffiliation(String affiliation) {
        this.affiliation = affiliation;
    }

    public void setEnrollment(Enrollment enrollment) {
        this.enrollment = enrollment;
    }

    /**
     * Get the name that identifies the user.
     *
     * @return the user name.
     */
    @Override
    public String getName() {
        return name;
    }

    /**
     * Get the roles to which the user belongs.
     *
     * @return role names.
     */
    @Override
    public Set<String> getRoles() {
        return roles;
    }

    /**
     * Get the user's account
     *
     * @return the account name
     */
    @Override
    public String getAccount() {
        return account;
    }

    /**
     * Get the user's affiliation.
     *
     * @return the affiliation.
     */
    @Override
    public String getAffiliation() {
        return affiliation;
    }

    /**
     * Get the user's enrollment certificate information.
     *
     * @return the enrollment information.
     */
    @Override
    public Enrollment getEnrollment() {
        return enrollment;
    }

    /**
     * Get the Membership Service Provider Identifier provided by the user's organization.
     *
     * @return MSP Id.
     */
    @Override
    public String getMspId() {
        return mspid;
    }
}



public class FCEnrollment implements Enrollment, Serializable {

    private static final long serialVersionUID = -4274445336349657179L;
    private PrivateKey key;
    private String cert;

    FCEnrollment(String signedPem, String key) {
        PrivateKey privateKey = null;
        try {
            privateKey = getPrivateKeyFromString(key);
        } ca
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值