-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
33 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,18 @@ | ||
//@nearfile | ||
import { near, context, storage, logging } from "near-runtime-ts"; | ||
import { Greeter } from "./model"; | ||
import { logging } from "near-runtime-ts"; | ||
// available class: near, context, storage, logging, base58, base64, | ||
// PersistentMap, PersistentVector, PersistentDeque, PersistentTopN, ContractPromise, math | ||
import { TextMessage } from "./model"; | ||
|
||
// --- contract code goes below | ||
const NAME = ". Welcome to NEAR Protocol chain" | ||
|
||
// It's good to use common constant, but not required. | ||
const LAST_SENDER_KEY = "last_sender"; | ||
|
||
// This is our change method. It modifies the state of the contract by | ||
// storing the account_id of the sender under the key "last_sender" on the blockchain | ||
export function sayHi(): void { | ||
// context.sender is the account_id of the user who sent this call to the contract | ||
// It's provided by the Blockchain runtime. For now we just store it in a local variable. | ||
let sender = context.sender; | ||
// `near` class contains some helper functions, e.g. logging. | ||
// Logs are not persistently stored on the blockchain, but produced by the blockchain runtime. | ||
// It's helpful to use logs for debugging your functions or when you need to get some info | ||
// from the change methods (since change methods don't return values to the front-end). | ||
logging.log(sender + " says \"Hello mate!\""); | ||
// storage is a helper class that allows contracts to modify the persistent state | ||
// and read from it. setString allows you to persitently store a string value for a given string key. | ||
// We'll store the last sender of this contract who called this method. | ||
storage.setString(LAST_SENDER_KEY, sender); | ||
export function welcome(name: string): TextMessage { | ||
logging.log("simple welcome test"); | ||
let message = new TextMessage() | ||
const s = printString(NAME); | ||
message.text = "Welcome, " + name + s; | ||
return message; | ||
} | ||
|
||
// This is our view method. It returns the last account_id of a sender who called `sayHi`. | ||
// It reads value from the persistent store under the key "last_sender" and returns it. | ||
export function whoSaidHi(): string | null { | ||
// getString returns a string value for a given string key. | ||
return storage.getString(LAST_SENDER_KEY); | ||
} | ||
function printString(s: string): string { | ||
return s; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
//@nearfile | ||
// Basic data model | ||
export class Greeter { | ||
text: string; | ||
|
||
constructor(text: string) { | ||
this.text = text; | ||
} | ||
|
||
greet(userId: string): string { | ||
return "Hello, " + userId; | ||
} | ||
} | ||
export class TextMessage { | ||
text: string; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters