Skip to content

Instantly share code, notes, and snippets.

Avatar

Vladimir Grichina vgrichina

View GitHub Profile
@vgrichina
vgrichina / set-contract-to-deploy.md
Created Jun 18, 2020
How to deploy contract from AssemblyScript
View set-contract-to-deploy.md

You can do following to allow passing blob into contract without a lot of overhead:

export function setContractToDeploy(): void {
     env.input(0);
     util.read_register(0);
     // ...
}
View custom_deploy.js
async function deploy(options) {
const configPath = process.cwd() + '/src/config';
const config = require(configPath)(process.env.NODE_ENV || 'development');
const near = await nearlib.connect({...config, deps: { keyStore: new UnencryptedFileSystemKeyStore('./neardev') } });
const contractData = [...fs.readFileSync(options.wasmFile)];
const account = await near.account(options.accountId);
await account.signAndSendTransaction(options.accountId, [
deployContract(contractData),
// TODO: Use whatever actual params need to be for functionCall or include any other actions as well
View gist:e3778f736a31cbdeaf5f1e3a744d9ebb
[I] ➜ yarn start
yarn run v1.21.1
warning package.json: No license field
$ npm run build && near deploy --wasmFile ./contract/res/status_message.wasm
npm WARN lifecycle The node binary used for scripts is /var/folders/3c/zjk2krns25s75x_z2_wdvgg80000gn/T/yarn--1580160108615-0.8711654915114355/node but npm is using /Users/vg/n/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
> blank-rust-proj-vg@0.0.1 build /Users/vg/Documents/create-near-app/blank-rust-proj-vg
> cd contract && ./build.sh
Updating crates.io index
@vgrichina
vgrichina / explorer-sqlite.js
Last active Jan 15, 2020
NEAR Explorer SQLite cheatsheet
View explorer-sqlite.js
sqlite3 = require('sqlite3')
db = new sqlite3.Database('db/testnet-database.sqlite')
db.all(`select name from sqlite_master where type='table'`, console.log)
db.all(`select * from transactions where actions like '%deploy%' limit 10`, console.log)
db.all(`select count(*) from transactions where actions like '%deploy%' limit 10`, console.log)
@vgrichina
vgrichina / load-test.js
Last active Sep 13, 2019
load testing nearcore payments
View load-test.js
const nearlib = require('nearlib');
const { signTransaction, transfer } = nearlib.transactions;
const { base_decode } = nearlib.utils.serialize;
const sleep = (ms) => new Promise((resolved) => setTimeout(resolved, ms));
(async () => {
const [,, accountId, txCount] = process.argv;
const near = await nearlib.connect({...require('near-shell/get-config')(), deps: { keyStore: new nearlib.keyStores.UnencryptedFileSystemKeyStore('./neardev') } });
@vgrichina
vgrichina / callback.js
Last active Jul 12, 2019
Spin up temporary webserver to handle callback from browser
View callback.js
const http = require('http');
const url = require('url');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
try {
@vgrichina
vgrichina / generated_bindings.ts
Last active Dec 7, 2018
Sample generated AssemblyScript BSON bindings
View generated_bindings.ts
import "allocator/arena";
// TODO: Why cannot import from index?
// import { BSONEncoder, BSONDecoder } from "../../../assemblyscript-bson/assembly";
import { BSONEncoder } from "../../../assemblyscript-bson/assembly/encoder";
import { BSONDecoder } from "../../../assemblyscript-bson/assembly/decoder";
declare function sayHello(): void;
export class FooBar {
foo: i32 = 0;
@vgrichina
vgrichina / booking.ts
Last active Nov 28, 2018
Booking train and hotel
View booking.ts
book_train_and_hotel() : void { // Needs 6 MANA.
// 3 for train and callback and 3 for hotel and callback.
// E.g. book_train and book_hotel doesn't need additional mana, so only 1 MANA for a call.
// Callback may need 1 additional to cancel train or hotel booking if one of them failed.
assert_has_mana(6);
let hotelBooking = bookHotel.withMana(3).withCoins(1000).book(sender());
let trainBooking = bookTrain.withMana(3).withCoins(1000).book(sender());
View ropes.hs
data Rope = Empty | Concat Int Rope Rope | Leaf String deriving (Show, Eq)
rope :: String -> Rope
rope "" = Empty
rope s = Leaf s
len :: Rope -> Int
len Empty = 0
len (Leaf s) = length s
len (Concat length _ _) = length
View gist:57796fb8d9a8ae41fc0d
/**
* CSV Parser. Takes a string as input and returns
* an array of arrays (for each row).
*
* @param input String, CSV input
* @param separator String, single character used to separate fields.
* Defaults to ","
* @param quote String, single character used to quote non-simple fields.
* Defaults to "\"".
*/
You can’t perform that action at this time.