Flint
概要
Ethereum Foundation Grant Wave 4で$120K
Caller Protections
関数をcallできるコントラクトのaddressを限定する
Solidityのmodiferを使ったcaller protectionと異なり、インターナル関数によるcallについてはコンパイル時にチェック
code: Flint(Scala)
// State declaration
contract Bank {
var manager: Address
}
// Functions are declared in protection blocks,
// which specify which users are allowed to call them.
Bank :: (manager) { // manager is a state property.
// Only manager of the Bank can call clear.
func clear(address: Address) {
// body
}
}
// Anyone can initialize the contract.
Bank :: (any) {
public init(manager: Address) {
self.manager = manager
}
}
Type States
コントラクトの「ステート」の列挙型
ステートマシンとしてコントラクトをモデル化するデザインパターンをより実装しやすくするため
こちらも同じく、インターナル関数によるcallについては静的チェック(?)
code: Flint(Scala)
// Enumeration of states.
contract Auction (Preparing, InProgress) {}
Auction @(Preparing, InProgress) :: caller <- (any) {
public init() {
// ...
become Preparing
}
}
Auction @(Preparing) :: (beneficiary) {
public mutating func setBeneficiary(beneficiary: Address) {
self.beneficiary = beneficiary
}
mutating func openAuction() -> Bool {
// ...
become InProgress
}
}
Asset types
「アセット」を扱うための型
Weiもこの型のインスタンスとして扱う
まだ仕様策定中?
code: Flint(Scala)
Bank :: account <- (balances.keys) {
@payable
mutating func deposit(implicit value: inout Wei) {
// Omitting this line causes a compiler warning: the value received should be recorded.
}
mutating func withdraw() {
// balancesaccount is automatically set to 0 before transferring. }
}
その他
Intの演算子はもともとover/underflow対策されている
Resouces
paper: Writing Safe Smart Contracts in Flint