首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Smart招标合同

Smart招标合同
EN

Ethereum用户
提问于 2018-11-21 07:59:33
回答 1查看 2K关注 0票数 3

在合同代表买卖双方协议的情况下,卖方需要为每一个新的投标发布一个新的合同/或在一个单一合同中的数组中的新条目,然后买方通过咨询不同的现有出价(合同/数组)来选择最合适的报价。

我的问题是,买家如何可以轻易地搜索和查询区块链,查看现有的标书(合同),然后为他选择非选定的合适的合同?

据我所知,买方需要知道不同合同的地址,然后将Tx发送给每个合同,以便阅读每个合同的投标内容,对吗?

在可靠的情况下实现这种业务逻辑的最佳设计是什么?

EN

回答 1

Ethereum用户

发布于 2018-11-21 09:19:35

由自己的合同代表每一个投标可能是不正确的。您可以设计一个契约,其中每个不同的拍卖都有自己的契约部署(类似于令牌的部署方式),但即使这样也可能不正确。如果对于如何运行出价/拍卖有一个定义良好的模式,那么您可能可以编写一个单独的智能契约来创建和管理这些事件。

在线评论:

代码语言:javascript
复制
pragma solidity ^0.4.25;

contract BiddingContract
{
    // Bids will have a user and an amount
    struct Bid {
        address user;
        uint bidAmount;
    }

    // This array will store the history of all bids
    // Due to the logic in this contract, bids will always be in acending price order
    Bid[] AllBids;

    // We will initialize the contract with a bid for 0 from 0x0
    constructor() public {
        AllBids.push(Bid(0x0, 0));
    }

    // Users will submit a bid here as _bidPrice
    function submitBid(uint _bidPrice) public {
        // The last index of the array is one less than the length
        uint lastIndex = AllBids.length - 1;
        // Ensure this bid is more than the current highest bid (the latest bid)
        require(_bidPrice > AllBids[lastIndex].bidAmount);
        // If it is, then push the new bid to the end of the array
        AllBids.push(Bid(msg.sender, _bidPrice));
    }

    // Getter function to return the "top bid", which is the last index of the array
    function getTopBid() public view returns (address, uint) {
        uint lastIndex = AllBids.length - 1;

        return (AllBids[lastIndex].user, AllBids[lastIndex].bidAmount);
    }

    // Getter function to return the total number of bids
    // Allows you to write a loop which goes through all the bids
    function getNumberOfBids() public view returns (uint) {
        return AllBids.length;
    }

    // Getter function to return a single bid from the array by index
    // Allows you to write a loop which goes through all the bids
    function getBid(uint index) public view returns (address, uint) {
        return (AllBids[index].user, AllBids[index].bidAmount);
    }
}

为了读取合同中的数据,我们提供了getter函数,这些函数将返回不同的投标信息。您可以使用诸如Web3.js和本地/托管节点之类的方法从前端调用这些函数。

同样,像这样的合同还没有准备好生产,只是简单地演示了一种构建简单投标合同的方法。

票数 2
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/62754

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档