Convert Bytes returned by a View into a frontend string without padding #1457
Answered
by
jeapostrophe
lorenzopolidori
asked this question in
Q&A
-
I think my problem might have a simple answer, but I can't find it after some attempts. I have this simple Reach programme: export const main = Reach.App(() => {
const A = Participant('Admin', {
...hasConsoleLogger,
onReady: Fun(true, Null),
name: Bytes(128),
url: Bytes(128),
hash: Bytes(32)
})
const ProjectView = View('View', {
name: Bytes(128),
url: Bytes(128),
hash: Bytes(32)
})
const Api = API('Api', {
updateName: Fun([Bytes(128)], Null),
updateMetadata: Fun([Bytes(128), Bytes(32)], Null),
stop: Fun([], Bool)
})
init()
A.only(() => {
const [projectName, metadataUrl, metadataHash] = declassify([interact.name, interact.url, interact.hash])
})
A.publish(projectName, metadataUrl, metadataHash)
A.interact.onReady(getContract())
A.interact.log('The project contract is ready')
const [done, name, url, hash] = parallelReduce([false, projectName, metadataUrl, metadataHash])
.define(() => {
ProjectView.name.set(name)
ProjectView.url.set(url)
ProjectView.hash.set(hash)
})
.invariant(balance() == 0)
.while(!done)
/**
* Update project name
*/
.api(Api.updateName, (newName, k) => {
k(null)
return [false, newName, url, hash]
})
/**
* Update project metadata
*/
.api(Api.updateMetadata, (newUrl, newHash, k) => {
k(null)
return [false, name, newUrl, newHash]
})
/**
* Stops this contract
*/
.api(
Api.stop,
() => {
assume(this == A)
},
() => 0,
k => {
const isAdmin = this == A
require(isAdmin)
k(isAdmin)
return [true, name, url, hash]
}
)
.timeout(false)
commit()
A.interact.log('The project contract is closing down...')
exit()
}) In my frontend test, I set However, when I call the view after successful deployment: const ctc = account.contract(backend, contract.getInfo())
const view = ctc.v.View
const name = await view.name()[1]
'project 1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' Is there a Reach |
Beta Was this translation helpful? Give feedback.
Answered by
jeapostrophe
Oct 7, 2022
Replies: 1 comment 2 replies
-
There is no such utility function; just use normal JS |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
lorenzopolidori
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is no such utility function; just use normal JS