1 Star 0 Fork 6

kitvv / tlang

forked from anycmd / tlang 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

tlang

一个类lisp语言

我准备去除区块链的虚拟机,因为虚拟机不是必要的,改以解释执行类list语言的形式表达智能合约,然后提供标准交易模板,普通交易使用交易模板进行,有复杂逻辑的交易由应用者使用tlang语言书写逻辑表达(也可以使用面向java、.net、js、go等语言的sdk书写,使用sdk书写的程序会自动翻译为tlang)。

案例

下面是用tlang书写的一段合约逻辑

这个合约的逻辑是:要么知道我的birthDay是2017-06-23 要么 给出pubKey和用对应的私钥对你的pubKeyHash的签名。

由合约调用者传入的三个参数赋值下面三个变量。

合约定义方定义逻辑,合约调用方定义数据。

合约调用方提供数据:

(define birthDay "{birthDay}")
(define pubKey "{pubKey}")
(define sign "{sign}")

上面的键值对来自合约调用者,数据是键值对,执行时直接把键值对加入作用域不需要拼代码从而没有注入代码的可能。

下面三行是智能合约的逻辑,这三行是死的不会被调用者注入代码。

合约定义方定义的逻辑:

(define pubKeyHash="8658cefd0c1cf0ff294d14a66278f5a5490a1f8e")
(define myBirthDayHash="d4a0f6c5b4bcbf2f5830eabed3daa7304fb794d6")
(or 
	(= (hash160 birthDay) myBirthDayHash) 
	(and 
		(= (hash160 pubKey) pubKeyHash) 
		(= (decrypt pubKey sign) pubKeyHash)))

and = hash160 or decrypt是系统函数。

如果提供checksig系统函数的话(= (decrypt pubKey sign) pubKeyHash)也可以是(checksig pubKey sign pubKeyHash)。

ps:话说,这个案例不好,因为生日可以被枚举出来,从今天往前推100年挨着计算每一天的hash然后跟myBirthDayHash比对的话就能取走被这个合约锁定的资产了。

The MIT License (MIT) Copyright (c) 2018 anycmd Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个类lisp语言,基于yinwang的yin语言java实现翻译成.NET实现而来。 展开 收起
C#
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C#
1
https://gitee.com/kitvv/tlang.git
git@gitee.com:kitvv/tlang.git
kitvv
tlang
tlang
master

搜索帮助