Skip to content

Commit f8c8736

Browse files
Merge pull request #63 from nearprotocol/update-hello-contract
Update hello contract to latest version
2 parents c4f05f5 + 33a6399 commit f8c8736

File tree

2 files changed

+31
-38
lines changed

2 files changed

+31
-38
lines changed

tests/near-bindgen/assembly/hello/main.ts

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
// @nearfile out
2-
// tslint:disable as-variables
1+
//@nearfile out
32
import { context, storage, ContractPromise, near, logging } from "near-runtime-ts";
43

54
import { PromiseArgs, InputPromiseArgs, MyCallbackResult, MyContractPromiseResult } from "./model";
6-
import { u128 } from 'bignum';
75

6+
import { u128 } from "bignum";
87

98
export function hello(name: string): string {
109

@@ -146,48 +145,43 @@ export function callPromise(args: PromiseArgs): void {
146145
let promise = ContractPromise.create(
147146
args.receiver,
148147
args.methodName,
149-
//@ts-ignore
150-
// tslint:disable-next-line: no-unsafe-any
151-
inputArgs.serialize(),
148+
inputArgs.encode().serialize(),
149+
args.gas,
152150
new u128(args.balance));
153151
if (args.callback) {
154152
inputArgs.args = args.callbackArgs;
155-
let callbackBalance = new u128(args.callbackBalance as u64);
153+
let callbackBalance = args.callbackBalance as u64;
154+
156155
promise = promise.then(
156+
context.contractName,
157157
args.callback,
158-
"Method name", //TODO
159-
//@ts-ignore
160-
// tslint:disable-next-line: no-unsafe-any
161-
inputArgs.serialize(),
162-
//@ts-ignore
163-
// tslint:disable-next-line: no-unsafe-any
164-
callbackBalance
158+
inputArgs.encode().serialize(),
159+
args.callbackGas,
160+
new u128(callbackBalance)
165161
);
166162
}
167163
promise.returnAsResult();
168164
}
169165

170-
// export function callbackWithName(args: PromiseArgs): MyCallbackResult {
171-
// let contractResults = ContractPromise.getResults();
172-
// let allRes = Array.create<MyContractPromiseResult>(contractResults.length);
173-
// for (let i = 0; i < contractResults.length; ++i) {
174-
// let res = contractResults[i];
175-
// allRes[i] = new MyContractPromiseResult();
176-
// allRes[i].ok = res.success;
177-
// if (allRes[i].ok && res.buffer != null && res.buffer.length > 0) {
178-
// allRes[i].r = decode<MyCallbackResult>(res.buffer);
179-
// }
180-
// }
181-
// let result: MyCallbackResult = {
182-
// rs: allRes,
183-
// n: context.contractName,
184-
// };
185-
// let bytes = result.serialize();
186-
// storage.setBytes("lastResult", bytes);
187-
// return result;
188-
// }
166+
export function callbackWithName(args: PromiseArgs): MyCallbackResult {
167+
let contractResults = ContractPromise.getResults();
168+
let allRes = Array.create<MyContractPromiseResult>(contractResults.length);
169+
for (let i = 0; i < contractResults.length; ++i) {
170+
allRes[i] = new MyContractPromiseResult();
171+
allRes[i].ok = (contractResults[i].status == 1);
172+
if (allRes[i].ok && contractResults[i].buffer != null && contractResults[i].buffer.length > 0) {
173+
allRes[i].r = MyCallbackResult.decode(contractResults[i].buffer);
174+
}
175+
}
176+
let result: MyCallbackResult = {
177+
rs: allRes,
178+
n: context.contractName,
179+
};
180+
let bytes = result.encode().serialize();
181+
storage.setBytes("lastResult", bytes);
182+
return result;
183+
}
189184

190185
export function getLastResult(): MyCallbackResult {
191186
return MyCallbackResult.decode(storage.getBytes("lastResult"));
192187
}
193-

tests/near-bindgen/assembly/hello/model.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
// @nearfile out
2-
1+
//@nearfile out
32
export class PromiseArgs {
43
receiver: string;
54
methodName: string;
65
args: PromiseArgs;
6+
gas: i32;
77
balance: i32;
88
callback: string;
99
callbackArgs: PromiseArgs;
1010
callbackBalance: i32;
11-
isbool: bool;
12-
str: string;
11+
callbackGas: i32;
1312
}
1413

1514
export class InputPromiseArgs {

0 commit comments

Comments
 (0)