DataDance

内部说明 · 链端适配 · 2026 年 11 月 19 日 Internal note · chain adapter · 19 November 2026

广告公司流水怎么上链 How an agency ledger is attested

给链端适配商家数据用。广告公司交的是已经结束的一个月,一行一笔已经结算的收入。明细留在商家端。链上只收这一个月收据的 SHA-256。合约沿用已经在 DDC 链上的 CommerceAttester,不为一张表新铸一枚数据代币。 For the chain adapter on merchant data. An agency submits one closed month, one settled revenue line per row. The rows stay on the merchant desk. The chain receives only the SHA-256 of that month’s receipt. Use the CommerceAttester already on the DDC chain. Do not mint a data token for a spreadsheet.

同一组内部页还有 2026 账本、报价 和 采买合同。商家端在 business.datadance.ai。链 ID 44508。 The same internal set has the 2026 book, the quote, and the purchase contracts. The merchant desk is business.datadance.ai. Chain id 44508.

01

放在现有的哪一层 Which existing layer

  • 数据包代币 — DataNFT 上链只铸 tokenId,tokenURI 指回 https://api.datadance.ai/metadata/ddcnft/{tokenId}。明细在库里的 dataRecords。这层适合一个可出售的数据包,不适合每个月的广告流水。 Pack token — a DataNFT mint writes a tokenId whose tokenURI points at https://api.datadance.ai/metadata/ddcnft/{tokenId}. The rows stay in dataRecords. That layer is a sellable pack, not a monthly agency ledger.
  • 采购收据 — 一笔卖出用 datadance.commerce.licence.v1。收据里有买卖双方、金额、条数、datasetBytesExcluded: true。哈希是这段 JSON 的 SHA-256。合约 attest(bytes32)。广告流水走这一层。 Purchase receipt — a sale uses datadance.commerce.licence.v1. The receipt carries the two orgs, the amount, the row count, and datasetBytesExcluded: true. The hash is the SHA-256 of that JSON. The contract is attest(bytes32). Agency revenue uses this layer.
  • 以前没上链的 — 多数明细从来没有进链,只是库里的行,或者只有一枚数据包代币。广告流水补的是月结收据的哈希,不是把历史 CSV 重放成交易。 What was never chained — most rows never went on chain. They are database rows, or only a pack token. This note adds a hash of the closed month. It does not replay historical CSV into transactions.

02

一行流水 One ledger row

一行是一个广告主、一张投放单、一个已结束月份里的一笔结算。金额用该币种的最小单位整数,美元就是分。还没发生的日期和编号用 JSON null,键不省略。同一个投放单号永远不变。 One row is one settled line for one advertiser, one insertion order, and one closed month. Amounts are integers in minor units. US dollars are cents. A date or id that has not happened yet is JSON null. Do not drop the key. An insertion-order id never changes.

键Key 类型Type 含义Meaning
rowIdstring这一行的稳定编号Stable id of this line
advertiserstring广告主Advertiser
agencystring广告公司Agency
insertionOrderIdstring投放单号Insertion order
periodstringYYYY-MM,UTC 月YYYY-MM, UTC month
currencystringISO 4217,例如 USDISO 4217, for example USD
mediaSpendint媒体花费,最小单位Media spend, minor units
agencyFeeint服务费,最小单位Agency fee, minor units
recognizedRevenueint本月确认收入,最小单位Recognized revenue, minor units
invoiceNumberstring | null发票号Invoice number
invoiceDatestring | nullYYYY-MM-DDYYYY-MM-DD
paidAmountint已收金额,未收为 0Amount collected, 0 if unpaid
paidAtstring | null到账时间,UTC,YYYY-MM-DDTHH:mm:ss.sssZCollected at, UTC, YYYY-MM-DDTHH:mm:ss.sssZ
sourceRefstring | null平台报表或合同编号Platform report or contract id

03

一个月一张收据 One receipt per month

键的顺序就是下面这个顺序。没有多余的键。三项金额是该月这些行的合计,单位与行相同。rowsHash 是行数组规范 JSON 的 SHA-256,小写十六进制,不带 0x。下个月是一张新收据。已经存证的收据不改。 Key order is the order below. No extra keys. The three amounts are the sums of that month’s rows, in the same minor units. rowsHash is the SHA-256 of the canonical JSON of the row array, lowercase hex, no 0x. The next month is a new receipt. An attested receipt is not edited.

  • schema — datadance.ad-revenue.statement.v1
  • version — 1
  • agencyOrgId — 广告公司在商家端的组织 idAgency org id on the merchant desk
  • advertiserOrgId — 广告主的组织 idAdvertiser org id
  • period — YYYY-MM
  • currency
  • mediaSpend / agencyFee / recognizedRevenue
  • rowCount
  • rowsHash
  • closedAt — 结账时间,UTCClose time, UTC

04

规范 JSON 和哈希 Canonical JSON and the hash

UTF-8。无空格,无换行。键按上面的顺序。字符串里的非 ASCII 不转成 \u。哈希是 SHA-256 的小写十六进制。先哈希行数组,再把结果写进收据,再哈希收据。链上参数是这个十六进制加上 0x,32 字节。 UTF-8. No spaces, no newline. Keys in the order above. Non-ASCII in strings stays as characters, not \u escapes. The hash is lowercase hex SHA-256. Hash the row array first, put that digest on the receipt, then hash the receipt. The chain argument is that hex with 0x, 32 bytes.

样例行。金额 100000 分是 $1,000.00。 Sample row. 100000 minor units is $1,000.00.

阅读排版 · 哈希按无空格的那一行 Reading layout · the hash uses the line with no spaces

[
  {
    "rowId": "IO-1001",
    "advertiser": "Example Brand",
    "agency": "Example Agency",
    "insertionOrderId": "IO-100",
    "period": "2026-10",
    "currency": "USD",
    "mediaSpend": 100000,
    "agencyFee": 15000,
    "recognizedRevenue": 115000,
    "invoiceNumber": "INV-1001",
    "invoiceDate": "2026-10-31",
    "paidAmount": 115000,
    "paidAt": "2026-11-05T00:00:00.000Z",
    "sourceRef": "platform-report-88"
  }
]

rowsHash de9045b1275c949ee6f2109d7b7dfcbc5e213bde88d439c976b727be2c780e24

月结收据 Month receipt

{
  "schema": "datadance.ad-revenue.statement.v1",
  "version": 1,
  "agencyOrgId": "org_agency_example",
  "advertiserOrgId": "org_advertiser_example",
  "period": "2026-10",
  "currency": "USD",
  "mediaSpend": 100000,
  "agencyFee": 15000,
  "recognizedRevenue": 115000,
  "rowCount": 1,
  "rowsHash": "de9045b1275c949ee6f2109d7b7dfcbc5e213bde88d439c976b727be2c780e24",
  "closedAt": "2026-11-01T00:00:00.000Z"
}

收据哈希,也就是 attest 的参数去掉 0x 之后 Receipt hash, the attest argument without 0x 05a1f03992f12182f17364bd46cb5edfdb74f730eaa7ca7d64f27f32d4ce977b

05

链上调用和库里留什么 The call, and what the database keeps

  • 合约 — CommerceAttester 0xe944f723af28659622425F62a49F48844C152a93,链 44508。function attest(bytes32 hash)。event Attested(bytes32 indexed hash, address indexed sender)。 Contract — CommerceAttester 0xe944f723af28659622425F62a49F48844C152a93, chain 44508. function attest(bytes32 hash). event Attested(bytes32 indexed hash, address indexed sender).
  • 接受一笔交易 — 回执 status 为 1,并且有一条 Attested 日志,哈希与这张收据完全一致。对不上就不要把交易号写进库。 Accept a transaction — receipt status is 1, and an Attested log carries exactly this receipt hash. Otherwise do not store the transaction hash.
  • 库里 — 行、收据 JSON、rowsHash、收据哈希、交易号、区块、存证时间。链上没有行,也没有发票文件。 In the database — the rows, the receipt JSON, rowsHash, the receipt hash, the transaction hash, the block, and the attested time. The chain has neither the rows nor the invoice file.
  • 不写进这张收据的 — 增长目标、银行账号、邮箱、整张 CSV。没有发票号或来源编号的数字先不要收进当月合计。 Leave out of the receipt — a growth target, bank accounts, email addresses, and the CSV itself. A figure with no invoice number and no source id stays out of that month’s sums.

06

和 Market SDK、7962 怎么分开 Where the Market SDK and 7962 stay out

后台的规范实现是 data-dance-backend/src/utils/adRevenueStatement.js 的 buildAdRevenueStatement。样例哈希以这个函数为准。Market SDK 那条 DDCNFT.mint(uint256 tokenId, bytes32 keyHash) 不要拿来铸这张月结。 The backend implementation is buildAdRevenueStatement in data-dance-backend/src/utils/adRevenueStatement.js. The sample hashes follow that function. Do not mint this month through the Market SDK call DDCNFT.mint(uint256 tokenId, bytes32 keyHash).

  • 现在上链 — 收据哈希交给 CommerceAttester attest(bytes32)。这和已经在用的采购许可收据是同一个合约、同一种 32 字节。链上证明这个月的表曾经是这一版。 What goes on chain now — the receipt hash goes to CommerceAttester attest(bytes32). Same contract and the same 32-byte value as a purchase-licence receipt. The chain shows that this month’s statement once had these bytes.
  • keyHash — Market SDK 里的 keyHash 是持有人。DDCNFT 的 ownerOf 返回的是 bytes32,不是地址。mint(tokenId, keyHash) 把一枚代币交给这把密钥。转手时用私钥对应的原文通过 keccak256(abi.encodePacked(key)) 证明。 keyHash — in the Market SDK a keyHash is an owner. DDCNFT ownerOf returns bytes32, not an address. mint(tokenId, keyHash) gives that key a token. A transfer proves the preimage with keccak256(abi.encodePacked(key)).
  • ERC-7962 — ERC-KeyHash721 和 ERC-KeyHash20 是这套持有方式的标准形态:余额挂在公钥哈希上,链上看不到钱包地址,别人可以代付 gas。它适合以后那笔还可以转手、又不想暴露持有人的权益。代币出来之前,积分仍然是账户账本。 ERC-7962 — ERC-KeyHash721 and ERC-KeyHash20 are the standard shape of that holding: a balance sits on a public-key hash, the chain has no wallet address, and someone else can pay gas. That fits a later claim that can move without revealing the holder. Until that token exists, points stay on the account ledger.
  • 不要混 — 月结哈希是这张表的 SHA-256。keyHash 是一把公钥的 keccak256。两个都是 bytes32,不能互换。7962 不存这张流水。这张流水也不为广告公司铸一枚会员代币。 Do not mix them — the month hash is the SHA-256 of this statement. A keyHash is keccak256 of a public key. Both are bytes32, and they are not interchangeable. 7962 does not store this ledger. This ledger does not mint a membership token for the agency.