Hello,
I'm following along the tutorial that demonstrates how to create a simple messaging app. Everything has been going great, but I have bumped into a couple of problems/confusion on this page:
Specifically, where does the code go that is described under "After our validation passes, we need to generate a key pair. To do this, we use modules.api.crypto.keypair". Is it in the callback of Message.prototype.add like this:
Message.prototype.add = function (cb, query) {
// Validate query object
library.validator.validate(query, {
type: "object",
properties: {
recipientId: {
type: "string",
minLength: 1,
maxLength: 21
},
secret: {
type: "string",
minLength: 1,
maxLength: 100
},
message: {
type: "string",
minLength: 1,
maxLength: 160
}
}
}, function (err) {
// If error exists, execute callback with error as first argument
if (err) {
return cb(err[0].message);
}
var keypair = modules.api.crypto.keypair(query.secret);
modules.blockchain.accounts.getAccount({
publicKey: keypair.publicKey.toString('hex')
}, function (err, account) {
// If error occurs, call cb with error argument
if (err) {
return cb(err);
}
// Create new transaction
try {
var transaction = library.modules.logic.transaction.create({
type: self.type,
message: query.message,
recipientId: query.recipientId,
sender: account,
keypair: keypair
});
} catch (e) {
// Catch error if something goes wrong
return setImmediate(cb, e.toString());
}
// Send transaction for processing
modules.blockchain.transactions.processUnconfirmedTransaction(transaction, cb);
});
});
}
A second issue I am having is with the command:
crypti-cli dapps --deposit
. I get the following error:
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' } undefined
Error: connect ECONNREFUSED
Is this a port/firewall issue or something else?
Finally, I am getting an error when trying to run the PUT for the first message:
curl -XPUT -H "Content-type: application/json" -d '{
"recipientId": "58191895912485C",
"message": "Hello, world!",
"secret": "mysecret"
}' 'http://[my_domain_and_port]/api/dapps/[dappid]/api/messages/add'
Error:
Cannot PUT /dapps/1719096962757412325/api/messages/add
Does the recipientId have to be something specific, or can it be any string? Any idea how to debug that?
Thanks!
Baz