In Corda, how can one party share with another an existing state in their vault?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















Suppose there are two nodes, Alice and Bob. Alice has a state she wants to make Bob aware of. How can Alice send the state to Bob and get him to store it in his vault?










share|improve this question




























    0















    Suppose there are two nodes, Alice and Bob. Alice has a state she wants to make Bob aware of. How can Alice send the state to Bob and get him to store it in his vault?










    share|improve this question
























      0












      0








      0








      Suppose there are two nodes, Alice and Bob. Alice has a state she wants to make Bob aware of. How can Alice send the state to Bob and get him to store it in his vault?










      share|improve this question














      Suppose there are two nodes, Alice and Bob. Alice has a state she wants to make Bob aware of. How can Alice send the state to Bob and get him to store it in his vault?







      corda






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 13:45









      JoelJoel

      11.5k11430




      11.5k11430






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You will need both an initiator and a responder flow:



          • The initiator will retrieve the state from its vault, retrieve the transaction that created this state, and send the transaction to the counterparty to be recorded

          • The responder will record the transaction, storing all its states

          Initiator flow



          @InitiatingFlow
          @StartableByRPC
          public class Initiator extends FlowLogic<Void>
          private final UUID stateId;
          private final Party otherParty;

          private final ProgressTracker progressTracker = new ProgressTracker();

          public Initiator(UUID stateId, Party otherParty)
          this.stateId = stateId;
          this.otherParty = otherParty;


          @Override
          public ProgressTracker getProgressTracker()
          return progressTracker;


          @Suspendable
          @Override
          public Void call() throws FlowException
          // Find the correct state.
          LinearStateQueryCriteria criteria = new LinearStateQueryCriteria(null, Collections.singletonList(stateId));
          Vault.Page<IOUState> queryResults = getServiceHub().getVaultService().queryBy(IOUState.class, criteria);
          if (queryResults.getStates().size() != 1)
          throw new IllegalStateException("Not exactly one match for the provided ID.");
          StateAndRef<IOUState> stateAndRef = queryResults.getStates().get(0);

          // Find the transaction that created this state.
          SecureHash creatingTransactionHash = stateAndRef.getRef().getTxhash();
          SignedTransaction creatingTransaction = getServiceHub().getValidatedTransactions().getTransaction(creatingTransactionHash);

          // Send the transaction to the counterparty.
          final FlowSession counterpartySession = initiateFlow(otherParty);
          subFlow(new SendTransactionFlow(counterpartySession, creatingTransaction));

          return null;




          Responder flow



          @InitiatedBy(Initiator.class)
          public class Responder extends FlowLogic<Void>
          private final FlowSession counterpartySession;

          public Responder(FlowSession counterpartySession)
          this.counterpartySession = counterpartySession;


          @Suspendable
          @Override
          public Void call() throws FlowException
          // Receive the transaction and store all its states.
          // If we don't pass `ALL_VISIBLE`, only the states for which the node is one of the `participants` will be stored.
          subFlow(new ReceiveTransactionFlow(counterpartySession, true, StatesToRecord.ALL_VISIBLE));

          return null;







          share|improve this answer























          • what about those txn in which Alice and other participants were involved but Bob . From above code , I can see bob will get these txn info , which does not seems good in some cases.

            – manish
            Nov 18 '18 at 16:41












          • In theory, you could just send the state, but then Bob would have to trust that the state was valid, and would not be able to store it in his vault. In the future, SGX will likely prevent nodes seeing parts of transactions not relevant to them.

            – Joel
            Nov 19 '18 at 15:42











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339102%2fin-corda-how-can-one-party-share-with-another-an-existing-state-in-their-vault%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You will need both an initiator and a responder flow:



          • The initiator will retrieve the state from its vault, retrieve the transaction that created this state, and send the transaction to the counterparty to be recorded

          • The responder will record the transaction, storing all its states

          Initiator flow



          @InitiatingFlow
          @StartableByRPC
          public class Initiator extends FlowLogic<Void>
          private final UUID stateId;
          private final Party otherParty;

          private final ProgressTracker progressTracker = new ProgressTracker();

          public Initiator(UUID stateId, Party otherParty)
          this.stateId = stateId;
          this.otherParty = otherParty;


          @Override
          public ProgressTracker getProgressTracker()
          return progressTracker;


          @Suspendable
          @Override
          public Void call() throws FlowException
          // Find the correct state.
          LinearStateQueryCriteria criteria = new LinearStateQueryCriteria(null, Collections.singletonList(stateId));
          Vault.Page<IOUState> queryResults = getServiceHub().getVaultService().queryBy(IOUState.class, criteria);
          if (queryResults.getStates().size() != 1)
          throw new IllegalStateException("Not exactly one match for the provided ID.");
          StateAndRef<IOUState> stateAndRef = queryResults.getStates().get(0);

          // Find the transaction that created this state.
          SecureHash creatingTransactionHash = stateAndRef.getRef().getTxhash();
          SignedTransaction creatingTransaction = getServiceHub().getValidatedTransactions().getTransaction(creatingTransactionHash);

          // Send the transaction to the counterparty.
          final FlowSession counterpartySession = initiateFlow(otherParty);
          subFlow(new SendTransactionFlow(counterpartySession, creatingTransaction));

          return null;




          Responder flow



          @InitiatedBy(Initiator.class)
          public class Responder extends FlowLogic<Void>
          private final FlowSession counterpartySession;

          public Responder(FlowSession counterpartySession)
          this.counterpartySession = counterpartySession;


          @Suspendable
          @Override
          public Void call() throws FlowException
          // Receive the transaction and store all its states.
          // If we don't pass `ALL_VISIBLE`, only the states for which the node is one of the `participants` will be stored.
          subFlow(new ReceiveTransactionFlow(counterpartySession, true, StatesToRecord.ALL_VISIBLE));

          return null;







          share|improve this answer























          • what about those txn in which Alice and other participants were involved but Bob . From above code , I can see bob will get these txn info , which does not seems good in some cases.

            – manish
            Nov 18 '18 at 16:41












          • In theory, you could just send the state, but then Bob would have to trust that the state was valid, and would not be able to store it in his vault. In the future, SGX will likely prevent nodes seeing parts of transactions not relevant to them.

            – Joel
            Nov 19 '18 at 15:42















          0














          You will need both an initiator and a responder flow:



          • The initiator will retrieve the state from its vault, retrieve the transaction that created this state, and send the transaction to the counterparty to be recorded

          • The responder will record the transaction, storing all its states

          Initiator flow



          @InitiatingFlow
          @StartableByRPC
          public class Initiator extends FlowLogic<Void>
          private final UUID stateId;
          private final Party otherParty;

          private final ProgressTracker progressTracker = new ProgressTracker();

          public Initiator(UUID stateId, Party otherParty)
          this.stateId = stateId;
          this.otherParty = otherParty;


          @Override
          public ProgressTracker getProgressTracker()
          return progressTracker;


          @Suspendable
          @Override
          public Void call() throws FlowException
          // Find the correct state.
          LinearStateQueryCriteria criteria = new LinearStateQueryCriteria(null, Collections.singletonList(stateId));
          Vault.Page<IOUState> queryResults = getServiceHub().getVaultService().queryBy(IOUState.class, criteria);
          if (queryResults.getStates().size() != 1)
          throw new IllegalStateException("Not exactly one match for the provided ID.");
          StateAndRef<IOUState> stateAndRef = queryResults.getStates().get(0);

          // Find the transaction that created this state.
          SecureHash creatingTransactionHash = stateAndRef.getRef().getTxhash();
          SignedTransaction creatingTransaction = getServiceHub().getValidatedTransactions().getTransaction(creatingTransactionHash);

          // Send the transaction to the counterparty.
          final FlowSession counterpartySession = initiateFlow(otherParty);
          subFlow(new SendTransactionFlow(counterpartySession, creatingTransaction));

          return null;




          Responder flow



          @InitiatedBy(Initiator.class)
          public class Responder extends FlowLogic<Void>
          private final FlowSession counterpartySession;

          public Responder(FlowSession counterpartySession)
          this.counterpartySession = counterpartySession;


          @Suspendable
          @Override
          public Void call() throws FlowException
          // Receive the transaction and store all its states.
          // If we don't pass `ALL_VISIBLE`, only the states for which the node is one of the `participants` will be stored.
          subFlow(new ReceiveTransactionFlow(counterpartySession, true, StatesToRecord.ALL_VISIBLE));

          return null;







          share|improve this answer























          • what about those txn in which Alice and other participants were involved but Bob . From above code , I can see bob will get these txn info , which does not seems good in some cases.

            – manish
            Nov 18 '18 at 16:41












          • In theory, you could just send the state, but then Bob would have to trust that the state was valid, and would not be able to store it in his vault. In the future, SGX will likely prevent nodes seeing parts of transactions not relevant to them.

            – Joel
            Nov 19 '18 at 15:42













          0












          0








          0







          You will need both an initiator and a responder flow:



          • The initiator will retrieve the state from its vault, retrieve the transaction that created this state, and send the transaction to the counterparty to be recorded

          • The responder will record the transaction, storing all its states

          Initiator flow



          @InitiatingFlow
          @StartableByRPC
          public class Initiator extends FlowLogic<Void>
          private final UUID stateId;
          private final Party otherParty;

          private final ProgressTracker progressTracker = new ProgressTracker();

          public Initiator(UUID stateId, Party otherParty)
          this.stateId = stateId;
          this.otherParty = otherParty;


          @Override
          public ProgressTracker getProgressTracker()
          return progressTracker;


          @Suspendable
          @Override
          public Void call() throws FlowException
          // Find the correct state.
          LinearStateQueryCriteria criteria = new LinearStateQueryCriteria(null, Collections.singletonList(stateId));
          Vault.Page<IOUState> queryResults = getServiceHub().getVaultService().queryBy(IOUState.class, criteria);
          if (queryResults.getStates().size() != 1)
          throw new IllegalStateException("Not exactly one match for the provided ID.");
          StateAndRef<IOUState> stateAndRef = queryResults.getStates().get(0);

          // Find the transaction that created this state.
          SecureHash creatingTransactionHash = stateAndRef.getRef().getTxhash();
          SignedTransaction creatingTransaction = getServiceHub().getValidatedTransactions().getTransaction(creatingTransactionHash);

          // Send the transaction to the counterparty.
          final FlowSession counterpartySession = initiateFlow(otherParty);
          subFlow(new SendTransactionFlow(counterpartySession, creatingTransaction));

          return null;




          Responder flow



          @InitiatedBy(Initiator.class)
          public class Responder extends FlowLogic<Void>
          private final FlowSession counterpartySession;

          public Responder(FlowSession counterpartySession)
          this.counterpartySession = counterpartySession;


          @Suspendable
          @Override
          public Void call() throws FlowException
          // Receive the transaction and store all its states.
          // If we don't pass `ALL_VISIBLE`, only the states for which the node is one of the `participants` will be stored.
          subFlow(new ReceiveTransactionFlow(counterpartySession, true, StatesToRecord.ALL_VISIBLE));

          return null;







          share|improve this answer













          You will need both an initiator and a responder flow:



          • The initiator will retrieve the state from its vault, retrieve the transaction that created this state, and send the transaction to the counterparty to be recorded

          • The responder will record the transaction, storing all its states

          Initiator flow



          @InitiatingFlow
          @StartableByRPC
          public class Initiator extends FlowLogic<Void>
          private final UUID stateId;
          private final Party otherParty;

          private final ProgressTracker progressTracker = new ProgressTracker();

          public Initiator(UUID stateId, Party otherParty)
          this.stateId = stateId;
          this.otherParty = otherParty;


          @Override
          public ProgressTracker getProgressTracker()
          return progressTracker;


          @Suspendable
          @Override
          public Void call() throws FlowException
          // Find the correct state.
          LinearStateQueryCriteria criteria = new LinearStateQueryCriteria(null, Collections.singletonList(stateId));
          Vault.Page<IOUState> queryResults = getServiceHub().getVaultService().queryBy(IOUState.class, criteria);
          if (queryResults.getStates().size() != 1)
          throw new IllegalStateException("Not exactly one match for the provided ID.");
          StateAndRef<IOUState> stateAndRef = queryResults.getStates().get(0);

          // Find the transaction that created this state.
          SecureHash creatingTransactionHash = stateAndRef.getRef().getTxhash();
          SignedTransaction creatingTransaction = getServiceHub().getValidatedTransactions().getTransaction(creatingTransactionHash);

          // Send the transaction to the counterparty.
          final FlowSession counterpartySession = initiateFlow(otherParty);
          subFlow(new SendTransactionFlow(counterpartySession, creatingTransaction));

          return null;




          Responder flow



          @InitiatedBy(Initiator.class)
          public class Responder extends FlowLogic<Void>
          private final FlowSession counterpartySession;

          public Responder(FlowSession counterpartySession)
          this.counterpartySession = counterpartySession;


          @Suspendable
          @Override
          public Void call() throws FlowException
          // Receive the transaction and store all its states.
          // If we don't pass `ALL_VISIBLE`, only the states for which the node is one of the `participants` will be stored.
          subFlow(new ReceiveTransactionFlow(counterpartySession, true, StatesToRecord.ALL_VISIBLE));

          return null;








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 13:45









          JoelJoel

          11.5k11430




          11.5k11430












          • what about those txn in which Alice and other participants were involved but Bob . From above code , I can see bob will get these txn info , which does not seems good in some cases.

            – manish
            Nov 18 '18 at 16:41












          • In theory, you could just send the state, but then Bob would have to trust that the state was valid, and would not be able to store it in his vault. In the future, SGX will likely prevent nodes seeing parts of transactions not relevant to them.

            – Joel
            Nov 19 '18 at 15:42

















          • what about those txn in which Alice and other participants were involved but Bob . From above code , I can see bob will get these txn info , which does not seems good in some cases.

            – manish
            Nov 18 '18 at 16:41












          • In theory, you could just send the state, but then Bob would have to trust that the state was valid, and would not be able to store it in his vault. In the future, SGX will likely prevent nodes seeing parts of transactions not relevant to them.

            – Joel
            Nov 19 '18 at 15:42
















          what about those txn in which Alice and other participants were involved but Bob . From above code , I can see bob will get these txn info , which does not seems good in some cases.

          – manish
          Nov 18 '18 at 16:41






          what about those txn in which Alice and other participants were involved but Bob . From above code , I can see bob will get these txn info , which does not seems good in some cases.

          – manish
          Nov 18 '18 at 16:41














          In theory, you could just send the state, but then Bob would have to trust that the state was valid, and would not be able to store it in his vault. In the future, SGX will likely prevent nodes seeing parts of transactions not relevant to them.

          – Joel
          Nov 19 '18 at 15:42





          In theory, you could just send the state, but then Bob would have to trust that the state was valid, and would not be able to store it in his vault. In the future, SGX will likely prevent nodes seeing parts of transactions not relevant to them.

          – Joel
          Nov 19 '18 at 15:42



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339102%2fin-corda-how-can-one-party-share-with-another-an-existing-state-in-their-vault%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          政党

          天津地下鉄3号線