Git Product home page Git Product logo

equity's Introduction

equity compiler tool

The equity compiler tool is the equity commandline compiler.

Requirements

Go version 1.8 or higher, with $GOPATH set to your preferred directory

Build source code, the build target of the equity compiler commandline tool is equity.

$ make equity

then change directory to equity, and you can find the commandline tool equity :

$ cd equity

Usage on the commandline

Usage of equity commandline compiler:

$ ./equity <input_file> [flags]

Using help provides you with an explanation of all options.

$ ./equity --help

available flags:

    --bin        Binary of the contracts in hex.
    --instance   Object of the Instantiated contracts.
    --shift      Function shift of the contracts.

Example

The contents of the contract file TradeOffer(without file suffix restrictions) are as follows:

contract TradeOffer(assetRequested: Asset,
                    amountRequested: Amount,
                    seller: Program,
                    cancelKey: PublicKey) locks valueAmount of valueAsset {
  clause trade() {
    lock amountRequested of assetRequested with seller
    unlock valueAmount of valueAsset
  }
  clause cancel(sellerSig: Signature) {
    verify checkTxSig(cancelKey, sellerSig)
    unlock valueAmount of valueAsset
  }
}
  • Compiler contract file to generate the binary:
./equity TradeOffer --bin

the return result:

======= TradeOffer =======
Binary:
547a6413000000007b7b51547ac1631a000000547a547aae7cac
  • Query the clause shift for contract:
./equity TradeOffer --shift

the return result:

======= TradeOffer =======
Clause shift:
    trade:  00000000
    cancel:  13000000
    ending:  1a000000

NOTE: If the contract contains only one clause, Users don't need clause selector when unlock contract. Furthermore, there is no signification for ending clause shift except for display.

  • Instantiated contract with arguments:
./equity TradeOffer --instance 84fe51a7739e8e2fe28e7042bb114fd6d6abd09cd22af867729ea001c87cd550 1000 0014d6598ab7dce6b04d43f31ad6eed76b18da553e94 7975f3f71ca7f55ecdef53ccf44224d514bc584bc065770bba8dcdb9d7f9ae6c

the return result:

======= TradeOffer =======
Instantiated program:
207975f3f71ca7f55ecdef53ccf44224d514bc584bc065770bba8dcdb9d7f9ae6c160014d6598ab7dce6b04d43f31ad6eed76b18da553e9402e8032084fe51a7739e8e2fe28e7042bb114fd6d6abd09cd22af867729ea001c87cd550741a547a6413000000007b7b51547ac1631a000000547a547aae7cac00c0

When you don't know the order of the contract parameters, you can use the prompt function:

./equity TradeOffer --instance

the commandline tips:

======= TradeOffer =======
Instantiated program:
Error: The number of input arguments 0 is less than the number of contract parameters 4
Usage:
  equity TradeOffer <assetRequested> <amountRequested> <seller> <cancelKey>

The input contract argument description:

type value description
Boolean true/1 , false/0
Integer 0 ~ 2^63-1
Amount -2^63 ~ 2^63-1
Asset hex string with length 64
Hash hex string with length 64
PublicKey hex string with length 64
Program hex string
String string with ASCII, e.g., "this is a test string"

equity's People

Contributors

colt-z avatar oysheng avatar paladz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

equity's Issues

Possible logical error in FixedLimitCollect & FixedLimitProfit contracts

Hi again,

I think there might be a logical error in FixedLimitCollect and, as a result, FixedLimitProfit:
https://github.com/Bytom/equity/blob/master/compiler/equitytest/FixedLimitCollect

Line 17: Gain is calculated as a percentage of the billAmount filled by the saver calling collect.
Hoever, other than verify gain > 0, gain is never used again.

In lines 20 and 24, FixedLimitProfit locks exactly the amount deposited by the saver, amountDeposited, without included profits. This means that when the contract expires after expireBlockHeight, savers are allowed to get their money back and nothing more. Essentially they just locked their own money away without receiving any profit.

What I think it should be:
define reward: Integer = amountDeposited + gain, as gain is define gain: Integer = sTotalAmountCapital * (sAmountDeposited/sTotalAmountBill)
and then, FixedLimitProfit should lock reward Amount of assets, which would be initial assets + profits as part of the capital.

Example workflow:
totalAmountBill: 1000
totalAmountCapital: 2000

I choose to lock away the full 1000 as a saver. I call collect with amountDeposited==1000:
gain==2000, as expected (the full reward)
However, in line 24: FixedLimitProfit only locks 1000 of my assets and nothing more. In line 21 of FixedLimitProfit, I get back my 1000 assets without anything else.

Compilation of contracts which use import "./fileInSameDirectory" fail

Good morning from Greece,

Compilation of all Smart Contracts in the equity/compiler/equitytest/ directory that use import "..." to reference another contract file lead to failure. More specifically when trying to compile FixedLimitCollect for example:

dimitris@dimitris-ThinkPad-T580:~/go/src/github.com/equity/equity$ ./equity /home/dimitris/go/src/github.com/equity/compiler/equitytest/FixedLimitCollect 

Compile contract failed: parse error: line 1, col 27: Check absolute path error: stat /home/dimitris/go/src/github.com/equity/equity/FixedLimitProfit: no such file or directory

By changing the line import "./FixedLimitProfit" to import "../compiler/equitytest/FixedLimitProfit" I was able to get the contract to be compiled just fine with the above command.
Do you think there's a problem with how the compiler parses the . operator during import?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.