Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sophia ML example #1543

Merged
merged 1 commit into from Sep 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions test/samples/sample.aes.txt
@@ -0,0 +1,38 @@
// Contract simulating developers organization
contract HackBG =

record state = { developers: map(address, developer) }

record developer = { name: string
, age: int
, skillset: map(skill, experience) }

type skill = string
type experience = int

datatype event =
LogDeveloperAdded(indexed address, indexed int, string)

entrypoint init() : state = { developers = {} }

stateful entrypoint dev_add(account: address, dev_name: string, dev_age: int) =
require(!is_member(account), "ERROR_DEVELOPER_ALREADY_EXISTS")
let dev : developer = { name = dev_name
, age = dev_age
, skillset = {} }
put(state{ developers[account] = dev })
Chain.event(LogDeveloperAdded(account, Chain.timestamp, dev_name))

stateful entrypoint dev_update(account: address, dev_name: string, dev_age: int) =
require(is_member(account), "ERROR_DEVELOPER_DOES_NOT_EXIST")
put(state{ developers[account].name = dev_name })
put(state{ developers[account].age = dev_age })

function is_member(account: address) : bool =
Map.member(account, state.developers)

stateful entrypoint dev_skill_modify(account: address, skill: string, experience: int) =
put(state{ developers[account].skillset[skill] = experience })

entrypoint dev_get(account: address) : developer =
state.developers[account]