无法在corda 4.0(java)中上载和下载显示为空的附件
上载和下载包含corda中文本文件的zip附件不起作用 尝试手动附加和下载zip文件,并尝试使用客户端RPC和代理发送附件 流程代码:无法在corda 4.0(java)中上载和下载显示为空的附件,corda,Corda,上载和下载包含corda中文本文件的zip附件不起作用 尝试手动附加和下载zip文件,并尝试使用客户端RPC和代理发送附件 流程代码: public class IOUFlow extends FlowLogic<Void> { private final Integer iouValue; private final Party otherParty; private final SecureHash attachmentHash; public
public class IOUFlow extends FlowLogic<Void> {
private final Integer iouValue;
private final Party otherParty;
private final SecureHash attachmentHash;
public IOUFlow(Integer iouValue, Party otherParty,SecureHash attachmentHash) {
this.iouValue = iouValue;
this.otherParty = otherParty;
this.attachmentHash=attachmentHash;
}
@Override
public ProgressTracker getProgressTracker() {
return progressTracker;
}
private static final Step ID_OTHER_NODES = new Step("Identifying other nodes on the network.");
private static final Step SENDING_AND_RECEIVING_DATA = new Step("Sending data between parties.");
private static final Step EXTRACTING_VAULT_STATES = new Step("Extracting states from the vault.");
private static final Step OTHER_TX_COMPONENTS = new Step("Gathering a transaction's other components.");
private static final Step TX_BUILDING = new Step("Building a transaction.");
private static final Step TX_SIGNING = new Step("Signing a transaction.");
private static final Step TX_VERIFICATION = new Step("Verifying a transaction.");
private static final Step SIGS_GATHERING = new Step("Gathering a transaction's signatures.") {
// Wiring up a child progress tracker allows us to see the
// subflow's progress steps in our flow's progress tracker.
@Override
public ProgressTracker childProgressTracker() {
return CollectSignaturesFlow.tracker();
}
};
private static final Step VERIFYING_SIGS = new Step("Verifying a transaction's signatures.");
private static final Step FINALISATION = new Step("Finalising a transaction.") {
@Override
public ProgressTracker childProgressTracker() {
return FinalityFlow.tracker();
}
};
private final ProgressTracker progressTracker = new ProgressTracker(
ID_OTHER_NODES,
SENDING_AND_RECEIVING_DATA,
EXTRACTING_VAULT_STATES,
OTHER_TX_COMPONENTS,
TX_BUILDING,
TX_SIGNING,
TX_VERIFICATION,
SIGS_GATHERING,
FINALISATION
);
@Suspendable
@Override
public Void call() throws FlowException {
progressTracker.setCurrentStep(ID_OTHER_NODES);
// We retrieve the notary identity from the network map.
Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
progressTracker.setCurrentStep(SENDING_AND_RECEIVING_DATA);
// We create the transaction components.
IOUState outputState = new IOUState(iouValue, getOurIdentity(), otherParty);
List<PublicKey> requiredSigners = Arrays.asList(getOurIdentity().getOwningKey(), otherParty.getOwningKey());
Command command = new Command<>(new IOUContract.Create(), requiredSigners);
TimeWindow ourAfter = TimeWindow.fromOnly(Instant.MIN);
progressTracker.setCurrentStep(TX_BUILDING);
// We create a transaction builder and add the components.
TransactionBuilder txBuilder = new TransactionBuilder(notary)
.addOutputState(outputState, IOUContract.ID)
.addCommand(command)
.addAttachment(attachmentHash);
// Verifying the transaction.
txBuilder.verify(getServiceHub());
progressTracker.setCurrentStep(TX_SIGNING);
// Signing the transaction.
SignedTransaction signedTx = getServiceHub().signInitialTransaction(txBuilder);
// Creating a session with the other party.
FlowSession otherPartySession = initiateFlow(otherParty);
// Obtaining the counterparty's signature.
SignedTransaction fullySignedTx = subFlow(new CollectSignaturesFlow(
signedTx, Arrays.asList(otherPartySession), CollectSignaturesFlow.tracker()));
progressTracker.setCurrentStep(TX_VERIFICATION);
// Finalising the transaction.
subFlow(new FinalityFlow(fullySignedTx, otherPartySession));
return null;
}
}
public类IOUFlow扩展了FlowLogic{
私有最终整数iouValue;
私人最终一方或另一方;
私人最终安全哈希附件;
公共IOUFlow(整数iouValue、Party otherParty、SecureHash attachmentHash){
this.iouValue=iouValue;
this.otherParty=另一方;
this.attachmentHash=attachmentHash;
}
@凌驾
公共ProgressTracker getProgressTracker(){
返回进程跟踪器;
}
私有静态最终步骤ID_OTHER_NODES=新步骤(“识别网络上的其他节点”);
私有静态最终步骤发送_和_接收_数据=新步骤(“在各方之间发送数据”);
私有静态最终步骤提取_VAULT_状态=新步骤(“从VAULT提取状态”);
私有静态最终步骤OTHER_TX_COMPONENTS=新步骤(“收集事务的其他组件”);
私有静态最终步骤TX_BUILDING=新步骤(“构建事务”);
私有静态最终步骤TX_SIGNING=新步骤(“签署交易”);
私有静态最终步骤TX_验证=新步骤(“验证事务”);
私有静态最终步骤SIGS_collection=新步骤(“收集事务的签名”){
//连接儿童进度跟踪器可以让我们看到
//子流的进度步骤位于流的进度跟踪器中。
@凌驾
公共ProgressTracker childProgressTracker(){
返回CollectSignaturesFlow.tracker();
}
};
私有静态最终步骤验证_SIGS=新步骤(“验证事务的签名”);
私有静态最终步骤完成=新步骤(“完成交易”){
@凌驾
公共ProgressTracker childProgressTracker(){
返回FinalityFlow.tracker();
}
};
private final ProgressTracker ProgressTracker=新ProgressTracker(
ID_其他_节点,
发送和接收数据,
提取"保险库"和"州",,
其他_-TX_组件,
德克萨斯大学大楼,
签署,
TX_验证,
SIGS_聚会,
定稿
);
@暂停
@凌驾
public Void call()引发流异常{
progressTracker.setCurrentStep(ID_其他_节点);
//我们从网络地图中检索公证人身份。
参与方公证人=getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
progressTracker.setCurrentStep(发送和接收数据);
//我们创建事务组件。
IOUState outputState=新IOUState(iouValue,getOurIdentity(),otherParty);
List requiredSigners=Arrays.asList(getOurIdentity().getOwningKey(),otherParty.getOwningKey());
Command Command=新命令(新IOUContract.Create(),requiredSigners);
TimeWindow-ourAfter=TimeWindow.fromOnly(Instant.MIN);
progressTracker.setCurrentStep(德克萨斯大学大楼);
//我们创建一个事务生成器并添加组件。
TransactionBuilder txBuilder=新TransactionBuilder(公证人)
.addOutputState(outputState,IOUContract.ID)
.addCommand(命令)
.添加附件(附件);
//验证事务。
验证(getServiceHub());
progressTracker.setCurrentStep(TX_签名);
//签署交易。
SignedTransaction signedTx=getServiceHub()。signInitialTransaction(txBuilder);
//正在与另一方创建会话。
FlowSession otherPartySession=initiateFlow(另一方);
//获得交易对手的签名。
SignedTransaction fullySignedTx=子流(新集合签名流(
signedTx,Arrays.asList(otherPartySession),CollectSignaturesFlow.tracker());
progressTracker.setCurrentStep(TX_验证);
//完成交易。
子流(新的最终流(fullySignedTx,otherPartySession));
返回null;
}
}
客户端代码:
public class Client {
private static final Logger logger = LoggerFactory.getLogger(Client.class);
public static void main(String[] args) throws Exception {
// Create an RPC connection to the node.
if (args.length != 3) throw new IllegalArgumentException("Usage: Client <node address> <rpc username> <rpc password>");
final NetworkHostAndPort nodeAddress = parse(args[0]);
final String rpcUsername = args[1];
final String rpcPassword = args[2];
final CordaRPCClient client = new CordaRPCClient(nodeAddress);
final CordaRPCOps proxy = client.start(rpcUsername, rpcPassword).getProxy();
// Interact with the node.
// For example, here we print the nodes on the network.
final List<NodeInfo> nodes = proxy.networkMapSnapshot();
logger.info("{}", nodes);
InputStream inputstream = new FileInputStream("corda.zip");
SecureHash hashId= proxy.uploadAttachment(inputstream);
System.out.println(hashId);
CordaX500Name x500Name = CordaX500Name.parse("O=ICICI,L=New York,C=US");
final Party otherParty = proxy.wellKnownPartyFromX500Name(x500Name);
/* proxy
.startFlowDynamic(IOUFlow.class, "10", otherParty,hashId)
.getReturnValue()
.get();*/
InputStream stream = proxy.openAttachment(hashId);
JarInputStream in = new JarInputStream(stream);
BufferedReader br =new BufferedReader(new InputStreamReader(in));
System.out.println("Output from attachment : "+br.readLine());
}
}
公共类客户端{
私有静态最终记录器Logger=LoggerFactory.getLogger(Client.class);
公共静态void main(字符串[]args)引发异常{
//创建到节点的RPC连接。
如果(args.length!=3)抛出新的IllegalArgumentException(“用法:客户端”);
最终NetworkHostAndPort nodeAddress=parse(args[0]);
最终字符串rpcUsername=args[1];
最后一个字符串rpcPassword=args[2];
最终CordaRPCClient=新CordaRPCClient(nodeAddress);
final CordaRPCOps proxy=client.start(rpcUsername,rpcPassword).getProxy();
//与节点交互。
//例如,这里我们打印网络上的节点。
最终列表节点=proxy.networkmapsnashot();
logger.info(“{}”,节点);
InputStream InputStream=新文件InputStream(“corda.zip”);
SecureHash hashId=proxy.uploadAttachment(inputstream);
System.out.println(hashId);
CordaX500Name x500Name=CordaX500Name.parse(“O=ICICI,L=newyork,C=US”);
最终一方otherParty=proxy.wellknownPartyFromX500名称(X500名称);
/*代理
.startFlowDynamic(IOUFlow.class,“10”,另一方,hashId)
.getReturnValue()
.get()*/
InputStream=proxy.openAttachment(hashId);
JarInputStream in=新的JarInputStream(流);
BufferedReader br=新的BufferedReader(新的InputStreamReader(in));
System.out.println(“从
A FlowLogicRef cannot be constructed for FlowLogic of type com.template.flows.IOUFlow: due to missing constructor for arguments: [class java.lang.String, class net.corda.core.identity.Party, class net.corda.core.crypto.SecureHash$SHA256]