27 lines
800 B
JavaScript
27 lines
800 B
JavaScript
|
import { Actor, Action } from './actor.js';
|
||
|
import { PostMessage } from './message.js';
|
||
|
import { CryptoUtil } from './crypto.js';
|
||
|
|
||
|
export class Member extends Actor {
|
||
|
constructor(name, scene) {
|
||
|
super(name, scene);
|
||
|
this.actions = {
|
||
|
submitPost: new Action('submit post', scene),
|
||
|
};
|
||
|
}
|
||
|
|
||
|
async initialize() {
|
||
|
this.keyPair = await CryptoUtil.generateSigningKey();
|
||
|
this.status.set('Initialized');
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
async submitPost(forumNode, post, stake) {
|
||
|
const postMessage = new PostMessage({ post, stake });
|
||
|
await postMessage.sign(this.keyPair);
|
||
|
this.actions.submitPost.log(this, forumNode, null, { id: post.id });
|
||
|
// For now, directly call forumNode.receiveMessage();
|
||
|
await forumNode.receiveMessage(JSON.stringify(postMessage.toJSON()));
|
||
|
}
|
||
|
}
|