forked from near-examples/near-crossword
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew-puzzle.js
162 lines (154 loc) · 4.32 KB
/
new-puzzle.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
This file is meant to be used as a demonstration of how to use
near-api-js to send a transaction that executes the FunctionCall Action.
For more snippets like this, please visit the cookbook here:
https://docs.near.org/docs/api/naj-cookbook
*/
const { connect, keyStores } = require("near-api-js");
const path = require("path");
const homedir = require("os").homedir();
const CREDENTIALS_DIR = ".near-credentials";
const CONTRACT_NAME = process.env.CONTRACT_NAME || "example.testnet";
const CREATOR_ACCOUNT_NAME = process.env.MASTER_ACCOUNT || process.env.CONTRACT_NAME || "example.testnet";
const credentialsPath = path.join(homedir, CREDENTIALS_DIR);
const keyStore = new keyStores.UnencryptedFileSystemKeyStore(credentialsPath);
const config = {
keyStore,
networkId: "testnet",
nodeUrl: "https://rpc.testnet.near.org",
};
sendTransactions();
async function sendTransactions() {
const near = await connect({ ...config, keyStore });
const account = await near.account(CONTRACT_NAME);
const newArgs = {
creator_account: CREATOR_ACCOUNT_NAME
};
const initResult = await account.functionCall({
contractId: CONTRACT_NAME,
methodName: "new",
args: Buffer.from(JSON.stringify(newArgs)),
gas: 300000000000000, // Optional, this is the maximum allowed case
});
const methodArgs = {
answer_pk: "ed25519:CpqWpFLps6zNNXSwn9ZYgvTgSVQ598fn1kWXgjcA2uLp",
dimensions: {
"x": 19,
"y": 13
},
answers: getPuzzleData()
};
const result = await account.functionCall({
contractId: CONTRACT_NAME,
methodName: "new_puzzle",
args: Buffer.from(JSON.stringify(methodArgs)),
gas: 300000000000000, // Optional, this is the maximum allowed case
attachedDeposit: '10000000000000000000000000', // Optional, 10 NEAR
});
console.log(`https://explorer.testnet.near.org/transactions/${initResult.transaction.hash}`, 'Init');
console.log(`https://explorer.testnet.near.org/transactions/${result.transaction.hash}`, 'Add Puzzle');
}
function getPuzzleData() {
return [
{
"num": 1,
"start": {
"x": 1,
"y": 2
},
"direction": "Across",
"length": 8,
"clue": "clue for sharding"
},
{
"num": 1,
"start": {
"x": 1,
"y": 2
},
"direction": "Down",
"length": 10,
"clue": "clue for subaccount"
},
{
"num": 2,
"start": {
"x": 0,
"y": 7
},
"direction": "Across",
"length": 9,
"clue": "clue for accesskey"
},
{
"num": 3,
"start": {
"x": 7,
"y": 4
},
"direction": "Down",
"length": 7,
"clue": "clue for indexer"
},
{
"num": 4,
"start": {
"x": 5,
"y": 5
},
"direction": "Across",
"length": 11,
"clue": "clue for nonfungible"
},
{
"num": 5,
"start": {
"x": 7,
"y": 10
},
"direction": "Across",
"length": 3,
"clue": "clue for rpc"
},
{
"num": 6,
"start": {
"x": 14,
"y": 1
},
"direction": "Down",
"length": 10,
"clue": "clue for simulation"
},
{
"num": 7,
"start": {
"x": 12,
"y": 2
},
"direction": "Across",
"length": 4,
"clue": "clue for init"
},
{
"num": 8,
"start": {
"x": 11,
"y": 8
},
"direction": "Across",
"length": 4,
"clue": "clue for defi"
},
{
"num": 8,
"start": {
"x": 11,
"y": 8
},
"direction": "Down",
"length": 3,
"clue": "clue for dao"
}
];
}