Tusshu
Tusshu

Reputation: 1734

How to pass secure hash to transaction builder

I uploaded a file to Corda node and got the following hex value as string back:

854AAE9BE6607CE0B15A70EEBEF19C553557103FB051413F2AA35E70F5B44313

Now I need to pass this as a secureHash parameter to transaction builder: txBuilder.addAttachment(??).

How to build secure hash from the hex string result obtained from file upload as input parameter to addAttachment..?

SecureHash has toString() function that returns hash as hex string above. I need to create secure hash using the hex string above.

Thanks.

Tried the following update to code: Added attachId parameter to IOUFlow in Hello World tutorial. Added attachment as txBuilder.addAttachment(attachId). See code below:

class IOUFlow(val iouValue: Int,
          val otherParty: Party, val attachId: SecureHash.SHA256) : 
 FlowLogic<Unit>() {

/** The progress tracker provides checkpoints indicating the progress of 
the flow to observers. */
override val progressTracker = ProgressTracker()

/** The flow logic is encapsulated within the call() method. */
@Suspendable
override fun call() {
    // We retrieve the notary identity from the network map.
    val notary = serviceHub.networkMapCache.notaryIdentities[0]
    val txBuilder = TransactionBuilder(notary = notary)
    txBuilder.addAttachment(attachId)
    ....
    }

Uploaded attachment to server and got following hash:

C5C84DADD15B2359EBDF0DFC6CCCAA48A0DBA3A04EFD8F03EB117186CC0B2D08

Started flow with following shell command:

start IOUFlow iouValue: 99, otherParty: "O=PartyB,L=New York,C=US”, attachId: C5C84DADD15B2359EBDF0DFC6CCCAA48A0DBA3A04EFD8F03EB117186CC0B2D08

Shell just responds with '>' and nothing happens. Have to use CTRL-C to get back shell prompt.

Upvotes: 1

Views: 247

Answers (1)

Joel
Joel

Reputation: 23140

Use SecureHash.parse() to convert the string to a SecureHash.

Upvotes: 1

Related Questions