-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get value from registry ? #32
Comments
good question! I hope we have a clear example / test for this soon. Yes, |
@fabcotech The high-level overview is this:
The best solution is to use a private name as @dckc suggested. Another option that may be easier for initial testing is to use a public name. Some examples of these techniques are in our live node test https://github.com/rchain-community/rchain-api/blob/master/test/liveRNodeTest.js#L48 You've given me a big push toward writing proper docs for this package! |
Ok here is how I did it ! Store the value on the chain: const rchain = RNode(grpc, {
host: HOST,
port: PORT,
});
const code = `
new
uriChannel,
private,
receiverChannel,
lookup(`rho:registry:lookup`),
insertArbitrary(`rho:registry:insertArbitrary`),
stdout(`rho:io:stdout`) in {
insertArbitrary!("store this data" , *uriChannel) |
for(uri <- uriChannel) {
lookup!(*uri, *receiverChannel) |
for(value <- receiverChannel) {
private!(*value) |
@"publicChannel"!(*private)
}
}
}`;
rchain
.doDeploy({
term: code,
timestamp: clock().valueOf(),
from: "0x1",
nonce: 0,
phloPrice: { value: 1 },
phloLimit: { value: 100000 }
})
.then(deployMessage => {
return rchain.createBlock();
})
.then(blockCreated => {
console.log("block created");
}); Retreive the value: rchain
.listenForDataAtPublicName("publicChannel")
.then(blockResults => {
return blockResults[0].postBlockData.slice(-1).pop();
})
.then(privateName => rchain.listenForDataAtName(privateName))
.then(blockResults => {
blockResults.forEach(b => {
b.postBlockData.forEach(d => {
logged("Value retreived : ", RHOCore.toRholang(d));
});
});
}); |
met with the same problem. how to convert |
@fabcotech that looks pretty close to the techniques I use in proxy.js, except that I use unforgeable names rather than public names. @ziqiDev writes:
/**
* Get printable form of unforgeable name, given id.
*/
exports.unforgeableWithId = unforgeableWithId;
function unforgeableWithId(id /*: Uint8Array */) {
const bytes = Writer.create().bytes(id).finish().slice(1);
return `Unforgeable(0x${b2h(bytes)})`;
}
exports.prettyPrivate = prettyPrivate;
function prettyPrivate(par /*: IPar */) {
if (!(par.ids && par.ids.length && par.ids[0].id)) { throw new Error('expected GPrivate'); }
return unforgeableWithId(par.ids[0].id);
} (currently in |
I see, but I want to convert it to |
|
Could I get |
yes, with I just (5878af2) added examples to the RHOCore section of the API docs. The Uri and ByteArray example should clarify: const { URL } = require('url');
const { RHOCore, Hex } = require('rchain-api');
const data = [new URL('rho:id:123'), Hex.decode('deadbeef')];
const rhoProto = RHOCore.fromJSData(data);
assert.deepEqual(RHOCore.toJSData(rhoProto), data);
assert.equal(RHOCore.toRholang(rhoProto),
'[`rho:id:123`, "deadbeef".hexToBytes()]'); |
In another contract I stored a value in the registry:
The returned address is
rho:id:pmc1cn6zff1pk5sf3purwby4zuqmwdiaj5xd7mu55usk88q5be9and
How can I get this value back in a node JS / web browser context using the rchain-api.js library ?
Is it by using the
listenForDataAtPublicName
orlistenForDataAtPrivateName
api ? Or something else ?The text was updated successfully, but these errors were encountered: