forked from near/near-sdk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic-updates-base.js
54 lines (47 loc) · 1.19 KB
/
basic-updates-base.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import {
NearBindgen,
call,
view,
near,
Vector,
ONE_NEAR
} from "near-sdk-js";
const POINT_ONE = ONE_NEAR / 10000n;
class PostedMessage {
constructor() {
this.premium = false;
this.sender = "";
this.text = "";
}
static new(premium, sender, text) {
let posted_message = new PostedMessage();
posted_message.premium = premium;
posted_message.sender = sender;
posted_message.text = text;
return posted_message;
}
}
@NearBindgen({})
export class GuestBook {
constructor() {
this.messages = new Vector("a");
this.payments = new Vector("b");
}
@call({payableFunction: true})
add_message({text}) {
const payment = near.attachedDeposit();
let premium = payment > POINT_ONE;
const sender = near.predecessorAccountId();
let message = PostedMessage.new(premium, sender, text);
this.messages.push(message);
this.payments.push(payment);
}
@view({})
get_message({ index }) {
return this.messages.get(index) || null;
}
@view({})
get_payment({ index }) {
return this.payments.get(index) || null;
}
}