# 10.3 订单模板谓词 (Order template predicate)

https://github.com/compolabs/spark/tree/master/services/predicate-orders-builder/order-template

This system uses a predicate to represent an order that can be filled by anyone. To create an order, the maker sends a coin to the predicate root, which can be unlocked by any transaction that meets the order's conditions. These conditions, such as transferring a specific amount of an asset to a receiver, are hard-coded into the predicate bytecode, making them specific to that order.

本系统使用一个谓词，来代表一个可以由任何人完成的订单。要创建一个订单，挂单方向谓词根发送一个代币，它可以被任何符合订单条件的交易解锁。这些条件，如将特定数量的资产转移给接收者，被硬编码到谓词字节码中，使其成为该订单的特定(属性)。

The order owner can then execute the order by spending the predicate coin in a transaction that meets the order's conditions. The owner can use the predicate coin in any way they wish, as long as the output of the transaction satisfies the order's conditions and is the first output in the output set.

然后，订单所有者可以通过在满足订单条件的交易中，花费谓词(相关的)代币来执行订单。只要交易的输出满足订单的条件，并且是输出集中的第一个输出，所有者可用以任何方式使用谓词代币。

To cancel an order, the maker can spend the predicate coin in a transaction that includes a single coin input signed by the receiver, with two inputs: the signed coin and the predicate coin.

为了取消订单，挂单方可以在交易中花费谓词相关的代币，包括由接收者签名的单一代币输入，其中有两个输入：签名代币和谓词代币。

Partially filled development in progress: that means an order can not be partially filled - the taker must pay the entire ask amount.

正在进行的部分替代开发：这意味着一个订单不能被部分满足--接受者必须支付整个要价金额。

> After updating to version 0.37.0 of the forc tool, the constants in the `forc.toml` file are now deprecated, which means we are required to insert the order data by modifying the `main.sw` file. The development team is currently working on a solution for this issue, and you can stay updated by following the forum topic dedicated to it: [https://forum.fuel.network/t/how-to-provide-constants-on-forc-v0-37-0-forc-toml-constants-outdated-on-forc-v0-37-0/2279/1](https://forum.fuel.network/t/how-to-provide-constants-on-forc-v0-37-0-forc-toml-constants-outdated-on-forc-v0-37-0/2279/1)
>
> 在更新到 forc工具的0.37.0版本后，`forc.toml`文件中的常量现在被废弃了，这意味着我们需要通过修改`main.sw` 文件来插入订单数据。开发团队目前正在努力解决这个问题，你可以通过关注论坛中专门的主题来了解最新情况： [https://forum.fuel.network/t/how-to-provide-constants-on-forc-v0-37-0-forc-toml-constants-outdated-on-forc-v0-37-0/2279/1](https://forum.fuel.network/t/how-to-provide-constants-on-forc-v0-37-0-forc-toml-constants-outdated-on-forc-v0-37-0/2279/1)​

​

```
predicate;
mod utils; 
use utils::*;
use std::{
    inputs::{
        input_count,
        input_owner,
    },
    outputs::{
        Output,
        output_amount,
        output_pointer,
        output_type,
    },
};

const AMOUNT0: u64 = <AMOUNT0>;
const ASSET0: b256 = <ASSET0>;
const AMOUNT1: u64 = <AMOUNT1>;
const ASSET1: b256 = <ASSET1>;
const OWNER: b256 = <OWNER>;
const ORDER_ID: str[30] = <ORDER_ID>;

const OUTPUT_COIN_INDEX = 0u8;

fn main() -> bool {
    let owner = Address::from(OWNER);
    if input_count() == 2u8 {
        if input_owner(0).unwrap() == owner || input_owner(1).unwrap() == owner
        {
            return true;
        };
    };

    // Otherwise, evaluate the terms of the order:
    // The output which pays the receiver must be the first output
    let output_index = 0;

    // Revert if output is not an Output::Coin
    match output_type(output_index) {
        Output::Coin => (),
        _ => revert(0),
    };

    // Since output is known to be a Coin, the following are always valid
    let to = Address::from(output_coin_to(output_index));
    let asset_id = ContractId::from(output_coin_asset_id(output_index));

    let amount = output_amount(output_index);

    // Evaluate the predicate
    (to == owner) && (amount == AMOUNT1) && (asset_id == ContractId::from(ASSET1))
}


```

​

During the development of this predicate, we were inspired by [OTC-swap-predicate](https://github.com/fuelLabs/sway-applications/tree/master/OTC-swap-predicate)

在这个谓词的开发过程中，我们受到了[OTC-交换-谓词](https://github.com/fuelLabs/sway-applications/tree/master/OTC-swap-predicate)的启发。
