Skip to content

Commit

Permalink
add 3 examples
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Oct 17, 2022
1 parent 1dec219 commit 703f00d
Show file tree
Hide file tree
Showing 30 changed files with 704 additions and 0 deletions.
1 change: 1 addition & 0 deletions add/.soroban/ledger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ledgerEntries":[[{"contractData":{"contractId":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8],"key":{"static":"ledgerKeyContractCode"}}},{"lastModifiedLedgerSeq":0,"data":{"contractData":{"contractId":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8],"key":{"static":"ledgerKeyContractCode"},"val":{"object":{"contractCode":{"wasm":[0,97,115,109,1,0,0,0,1,26,5,96,2,127,126,1,126,96,1,126,1,126,96,1,126,1,127,96,2,126,126,1,126,96,0,0,2,7,1,1,120,1,57,0,1,3,5,4,0,2,3,4,5,3,1,0,0,7,27,3,3,97,100,100,0,3,6,109,101,109,111,114,121,2,0,8,115,100,107,115,116,97,114,116,0,4,10,123,4,57,0,32,0,65,255,1,113,65,8,73,32,1,66,128,128,128,128,128,128,128,128,16,84,113,69,4,64,65,6,66,8,16,1,16,0,26,11,32,0,65,1,116,65,255,1,113,173,32,1,66,4,134,132,66,1,132,11,42,0,65,0,32,0,66,1,136,66,7,131,167,65,1,70,32,0,66,1,131,80,27,69,4,64,65,6,66,8,16,1,16,0,26,11,32,0,66,4,136,167,11,16,0,65,1,32,0,16,2,32,1,16,2,106,173,16,1,11,3,0,1,11,0,30,17,99,111,110,116,114,97,99,116,101,110,118,109,101,116,97,118,48,0,0,0,0,0,0,0,0,0,0,0,23,0,63,14,99,111,110,116,114,97,99,116,115,112,101,99,118,48,0,0,0,0,0,0,0,3,97,100,100,0,0,0,0,2,0,0,0,1,97,0,0,0,0,0,0,2,0,0,0,1,98,0,0,0,0,0,0,2,0,0,0,1,0,0,0,2]}}}}},"ext":"v0"}]],"protocolVersion":19,"sequenceNumber":1,"timestamp":5,"networkPassphrase":[76,111,99,97,108,32,83,97,110,100,98,111,120,32,83,116,101,108,108,97,114,32,78,101,116,119,111,114,107,32,59,32,83,101,112,116,101,109,98,101,114,32,50,48,50,50],"baseReserve":0}
13 changes: 13 additions & 0 deletions add/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "as-soroban-sdk/sdkasconfig",
"targets": {
"release": {
"outFile": "build/release.wasm",
"textFile": "build/release.wat"
},
"debug": {
"outFile": "build/debug.wasm",
"textFile": "build/debug.wat"
}
}
}
9 changes: 9 additions & 0 deletions add/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as val from 'as-soroban-sdk/lib/value';

export function add(a: val.RawVal, b: val.RawVal): val.RawVal {

let ai32 = val.toI32(a);
let bi32 = val.toI32(b);

return (val.fromI32(ai32 + bi32));
}
6 changes: 6 additions & 0 deletions add/assembly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "assemblyscript/std/assembly.json",
"include": [
"./**/*.ts"
]
}
2 changes: 2 additions & 0 deletions add/build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
16 changes: 16 additions & 0 deletions add/contract.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "add",
"version": "0.0.1",
"description": "soroban contract example adding 2 integers",
"host_functions_version": 23,
"functions": [
{
"name" : "add",
"arguments": [
{"name": "a", "type": "i32"},
{"name": "b", "type": "i32"}
],
"returns" : "i32"
}
]
}
10 changes: 10 additions & 0 deletions add/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script type="module">
import { add } from "./build/release.js";
document.body.innerText = add(1, 2);
</script>
</head>
<body></body>
</html>
140 changes: 140 additions & 0 deletions add/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions add/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "add",
"version": "0.0.1",
"description": "as soroban contract example adding two integers",
"main": "index.js",
"scripts": {
"test": "node tests",
"asbuild:debug": "asc assembly/index.ts --target debug",
"asbuild:release": "asc assembly/index.ts --target release",
"asbuild": "npm run asbuild:debug && npm run asbuild:release",
"start": "npx serve ."
},
"keywords": [
"soroban",
"example",
"add"
],
"author": "c.r.",
"license": "Apache-2.0",
"devDependencies": {
"assemblyscript": "^0.21.6"
},
"type": "module",
"exports": {
".": {
"import": "./build/release.js",
"types": "./build/release.d.ts"
}
},
"dependencies": {
"as-soroban-sdk": "^0.0.1"
}
}
4 changes: 4 additions & 0 deletions add/tests/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import assert from "assert";
import { add } from "../build/debug.js";
assert.strictEqual(add(1, 2), 3);
console.log("ok");
1 change: 1 addition & 0 deletions hello_word/.soroban/ledger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ledgerEntries":[[{"contractData":{"contractId":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6],"key":{"static":"ledgerKeyContractCode"}}},{"lastModifiedLedgerSeq":0,"data":{"contractData":{"contractId":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6],"key":{"static":"ledgerKeyContractCode"},"val":{"object":{"contractCode":{"wasm":[0,97,115,109,1,0,0,0,1,21,4,96,1,126,1,126,96,2,126,126,1,126,96,2,127,126,1,126,96,0,0,2,25,4,1,120,1,57,0,0,1,118,1,95,0,0,1,118,1,52,0,1,1,118,1,54,0,1,3,4,3,2,0,3,5,3,1,0,1,6,11,2,127,1,65,0,11,127,1,65,0,11,7,29,3,5,104,101,108,108,111,0,5,6,109,101,109,111,114,121,2,0,8,115,100,107,115,116,97,114,116,0,6,12,1,6,10,144,4,3,57,0,32,0,65,255,1,113,65,8,73,32,1,66,128,128,128,128,128,128,128,128,16,84,113,69,4,64,65,6,66,8,16,4,16,0,26,11,32,0,65,1,116,65,255,1,113,173,32,1,66,4,134,132,66,1,132,11,193,3,2,6,127,2,126,65,2,66,0,16,4,16,1,33,8,35,0,34,4,65,4,106,34,1,65,28,106,34,5,63,0,34,3,65,16,116,65,15,106,65,112,113,34,6,75,4,64,32,3,32,5,32,6,107,65,255,255,3,106,65,128,128,124,113,65,16,118,34,6,32,3,32,6,74,27,64,0,65,0,72,4,64,32,6,64,0,65,0,72,4,64,0,11,11,11,32,5,36,0,32,4,65,28,54,2,0,32,1,65,4,107,34,3,65,0,54,2,4,32,3,65,0,54,2,8,32,3,65,3,54,2,12,32,3,65,8,54,2,16,32,1,66,0,55,3,16,32,1,32,8,55,3,16,65,156,9,40,2,0,65,1,118,65,10,75,4,64,65,6,66,8,16,4,16,0,26,11,3,64,32,2,65,156,9,40,2,0,65,1,118,72,4,64,32,2,65,156,9,40,2,0,65,1,118,79,4,127,65,127,5,32,2,65,1,116,65,160,9,106,47,1,0,11,34,3,65,250,0,76,32,3,65,48,78,113,4,64,32,7,66,6,134,33,8,66,0,33,7,32,3,65,255,1,113,65,223,0,70,4,64,66,1,33,7,5,32,3,65,255,1,113,34,4,65,57,77,32,4,65,48,79,113,4,64,32,3,65,255,1,113,173,66,46,125,33,7,5,32,3,65,255,1,113,34,4,65,218,0,77,32,4,65,193,0,79,113,4,64,32,3,65,255,1,113,173,66,53,125,33,7,5,32,3,65,255,1,113,34,4,65,250,0,77,32,4,65,225,0,79,113,4,64,32,3,65,255,1,113,173,66,59,125,33,7,5,65,6,66,8,16,4,16,0,26,11,11,11,11,32,7,32,8,132,33,7,5,65,6,66,8,16,4,16,0,26,11,32,2,65,1,106,33,2,12,1,11,11,65,4,32,7,16,4,33,7,32,1,32,1,41,3,16,32,7,16,2,55,3,16,32,1,32,1,41,3,16,32,0,16,3,55,3,16,32,1,41,3,16,11,17,0,35,1,4,64,15,11,65,1,36,1,65,172,9,36,0,11,11,141,1,6,0,65,140,8,11,1,60,0,65,152,8,11,47,1,0,0,0,40,0,0,0,65,0,108,0,108,0,111,0,99,0,97,0,116,0,105,0,111,0,110,0,32,0,116,0,111,0,111,0,32,0,108,0,97,0,114,0,103,0,101,0,65,204,8,11,1,60,0,65,216,8,11,37,1,0,0,0,30,0,0,0,126,0,108,0,105,0,98,0,47,0,114,0,116,0,47,0,115,0,116,0,117,0,98,0,46,0,116,0,115,0,65,140,9,11,1,28,0,65,152,9,11,17,1,0,0,0,10,0,0,0,72,0,101,0,108,0,108,0,111,0,30,17,99,111,110,116,114,97,99,116,101,110,118,109,101,116,97,118,48,0,0,0,0,0,0,0,0,0,0,0,23,0,55,14,99,111,110,116,114,97,99,116,115,112,101,99,118,48,0,0,0,0,0,0,0,5,104,101,108,108,111,0,0,0,0,0,0,1,0,0,0,2,116,111,0,0,0,0,0,6,0,0,0,1,0,0,0,0]}}}}},"ext":"v0"}]],"protocolVersion":19,"sequenceNumber":1,"timestamp":5,"networkPassphrase":[76,111,99,97,108,32,83,97,110,100,98,111,120,32,83,116,101,108,108,97,114,32,78,101,116,119,111,114,107,32,59,32,83,101,112,116,101,109,98,101,114,32,50,48,50,50],"baseReserve":0}
13 changes: 13 additions & 0 deletions hello_word/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "as-soroban-sdk/sdkasconfig",
"targets": {
"release": {
"outFile": "build/release.wasm",
"textFile": "build/release.wat"
},
"debug": {
"outFile": "build/debug.wasm",
"textFile": "build/debug.wat"
}
}
}
11 changes: 11 additions & 0 deletions hello_word/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as val from 'as-soroban-sdk/lib/value';
import {Vec} from 'as-soroban-sdk/lib/vec';

export function hello(to: val.SymbolVal): val.VectorObject {

let vec = new Vec();
vec.push_front(val.fromString("Hello"));
vec.push_back(to);

return vec.getHostObject();
}
6 changes: 6 additions & 0 deletions hello_word/assembly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "assemblyscript/std/assembly.json",
"include": [
"./**/*.ts"
]
}
2 changes: 2 additions & 0 deletions hello_word/build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
13 changes: 13 additions & 0 deletions hello_word/contract.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "hello word",
"version": "0.0.1",
"description": "my first contract",
"host_functions_version": 23,
"functions": [
{
"name" : "hello",
"arguments": [{"name": "to", "type": "symbol"}],
"returns" : "val"
}
]
}
10 changes: 10 additions & 0 deletions hello_word/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script type="module">
import { add } from "./build/release.js";
document.body.innerText = add(1, 2);
</script>
</head>
<body></body>
</html>
Loading

0 comments on commit 703f00d

Please sign in to comment.