forked from IceSeaOnly/SaltedFish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
无聊的咸鱼.js
66 lines (56 loc) · 1.33 KB
/
无聊的咸鱼.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
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
var SaltedFish = function (text) {
if (text) {
var o = JSON.parse(text);
this.num = o.num;
this.from = o.from;
}
};
SaltedFish.prototype = {
toString: function () {
return JSON.stringify(this);
}
};
var BoringBoard = function () {
LocalContractStorage.defineProperty(this, "fish");
LocalContractStorage.defineMapProperty(this, "boringBoard", {
parse: function (text) {
return new SaltedFish(text);
},
stringify: function (o) {
return o.toString();
}
});
};
BoringBoard.prototype = {
init: function () {this.fish = 0;},
iAmSaltedFish:function(){
var from = Blockchain.transaction.from;
for(var i = 0; i < this.fish;i++){
var sf = this.getFish(i);
if(sf.from == from){
sf.num += 1;
this.boringBoard.put(i,sf);
return sf;
}
}
var sf = new SaltedFish();
sf.num = 1;
sf.from = from;
this.boringBoard.put(this.fish,sf);
this.fish += 1;
return sf;
},
getFish:function(index){
return this.boringBoard.get(index);
},
fishList:function(){
var list = [];
for(var i = 0; i < this.fish;i++){
var sf = this.getFish(i);
list.push(sf);
}
return list;
},
};
module.exports = BoringBoard;