Full Error message is below..
C:\Users\Education Use\crypto\app\pubsub.js:66
inputAddress: this.wallet.publicKey
^
TypeError: Cannot read property 'publicKey' of undefined
at Object.message (C:\Users\Education Use\crypto\app\pubsub.js:66:55)
at C:\Users\Education Use\crypto\node_modules\pubnub\lib\core\components\listener_manager.js:70:40
at Array.forEach (<anonymous>)
at _default.announceMessage (C:\Users\Education Use\crypto\node_modules\pubnub\lib\core\components\listener_manager.js:69:23)
at C:\Users\Education Use\crypto\node_modules\pubnub\lib\core\components\subscription_manager.js:712:35
at Array.forEach (<anonymous>)
at _default._processSubscribeResponse (C:\Users\Education Use\crypto\node_modules\pubnub\lib\core\components\subscription_manager.js:579:16)
at onResponse (C:\Users\Education Use\crypto\node_modules\pubnub\lib\core\components\endpoint.js:252:7)
at C:\Users\Education Use\crypto\node_modules\pubnub\lib\networking\modules\web-node.js:100:12
at Request.callback (C:\Users\Education Use\crypto\node_modules\superagent\lib\node\index.js:716:12)
const PubNub = require('pubnub');
const credentials = {
publishKey: 'pub-c-80cb1b82-bec3-46ec-bd1d-5ecfbdc7b268',
subscribeKey: 'sub-c-9246a854-b768-11ea-bf7c-ae6a3e72d19d',
secretKey: 'sec-c-YTA3ZmIwODYtNTI3Ni00ZWVkLWI0ZDYtMTlmY2QyNzM2Mzg0'
};
const CHANNELS = {
TEST: 'TEST',
BLOCKCHAIN: 'BLOCKCHAIN',
TRANSACTION: 'TRANSACTION'
};
class PubSub{
constructor({ blockchain, transactionPool }) {
this.blockchain = blockchain;
this.transactionPool = transactionPool;
// this.wallet = wallet;
this.pubnub = new PubNub(credentials);
this.pubnub.subscribe({ channels: [Object.values(CHANNELS)] });
this.pubnub.addListener(this.listener());
}
broadcastChain() {
this.publish({
channel: CHANNELS.BLOCKCHAIN,
message: JSON.stringify(this.blockchain.chain)
});
}
broadcastTransaction(transaction) {
this.publish({
channel: CHANNELS.TRANSACTION,
message: JSON.stringify(transaction)
});
}
subscribeToChannels() {
this.pubnub.subscribe({
channels: [Object.values(CHANNELS)]
});
}
listener() {
return {
message: messageObject => {
const { channel, message } = messageObject;
console.log(`Message received. Channel: ${channel}. Message: ${message}`);
const parsedMessage = JSON.parse(message);
switch(channel) {
case CHANNELS.BLOCKCHAIN:
this.blockchain.replaceChain(parsedMessage, true, () => {
this.transactionPool.clearBlockchainTransactions(
{ chain: parsedMessage.chain }
);
});
break;
case CHANNELS.TRANSACTION:
if (!this.transactionPool.existingTransaction({
inputAddress: this.wallet.publicKey
})) {
this.transactionPool.setTransaction(parsedMessage);
}
break;
default:
return;
}
}
}
}
publish({ channel, message }) {
// there is an unsubscribe function in pubnub
// but it doesn't have a callback that fires after success
// therefore, redundant publishes to the same local subscriber will be accepted as noisy no-ops
this.pubnub.publish({ message, channel });
}
broadcastChain() {
this.publish({
channel: CHANNELS.BLOCKCHAIN,
message: JSON.stringify(this.blockchain.chain)
});
}
broadcastTransaction(transaction) {
this.publish({
channel: CHANNELS.TRANSACTION,
message: JSON.stringify(transaction)
});
}
}
module.exports = PubSub;
What can be the issue and how can I resolve this... please guide anyone.