예제 #1
0
    public void CreateCatIsContract()
    {
        var result = Create <Cat>(0, new object[] { CatCounter });

        UpdateLastCreatedCat(result.NewContractAddress);
        PersistentState.SetBool("IsContract", PersistentState.IsContract(result.NewContractAddress));
    }
예제 #2
0
    /// <summary>
    /// Add an order receipt to the contract.
    /// </summary>
    /// <param name="order"></param>
    /// <param name="token"></param>
    public void AddOrder(Address order, Address token)
    {
        Assert(PersistentState.IsContract(order) &&
               PersistentState.IsContract(token));

        Log(new OrderLog
        {
            Owner = Message.Sender,
            Token = token,
            Order = order,
            Block = Block.Number
        });
    }
    /// <summary>
    /// Constructor creating a simple sell order setting the token, price, and amount to sell.
    /// </summary>
    /// <param name="smartContractState">The execution state for the contract.</param>
    /// <param name="token">The address of the src token being sold.</param>
    /// <param name="price">The price for each src token in stratoshis.</param>
    /// <param name="amount">The amount of src token to sell in full.</param>
    public SimpleSellOrder(ISmartContractState smartContractState, Address token, ulong price, ulong amount)
        : base(smartContractState)
    {
        Assert(price > 0, "Price must be greater than 0");
        Assert(amount > 0, "Amount must be greater than 0");
        Assert(PersistentState.IsContract(token), "Not a valid token address");

        Token    = token;
        Price    = price;
        Amount   = amount;
        Seller   = Message.Sender;
        IsActive = true;
    }
예제 #4
0
    /// <summary>
    /// Add an updated order receipt to the contract.
    /// </summary>
    /// <param name="order">The address of the order contract.</param>
    /// <param name="token">The address of the src token used in the order.</param>
    /// <param name="orderTxHash">The transactionHash of the order transaction.</param>
    public void UpdateOrder(Address order, Address token, string orderTxHash)
    {
        Assert(PersistentState.IsContract(order) &&
               PersistentState.IsContract(token) &&
               !string.IsNullOrEmpty(orderTxHash));

        Log(new UpdatedOrderLog
        {
            Token       = token,
            Order       = order,
            OrderTxHash = orderTxHash,
            Block       = Block.Number
        });
    }
예제 #5
0
    /// <summary>
    /// Constructor creating a simple buy order setting the token, price, and amount to buy.
    /// </summary>
    /// <param name="smartContractState">The execution state for the contract.</param>
    /// <param name="token">The address of the src token being bought.</param>
    /// <param name="price">The price for each src token in stratoshis.</param>
    /// <param name="amount">The amount of src token to buy in full.</param>
    public SimpleBuyOrder(
        ISmartContractState smartContractState,
        Address token,
        ulong price,
        ulong amount) : base(smartContractState)
    {
        Assert(price > 0, "Price must be greater than 0");
        Assert(amount > 0, "Amount must be greater than 0");
        Assert(Message.Value >= amount * price, "Balance is not enough to cover cost");
        Assert(PersistentState.IsContract(token), "Not a valid token address");

        Token    = token;
        Price    = price;
        Amount   = amount;
        Buyer    = Message.Sender;
        IsActive = true;
    }