---
# System prepended metadata

title: 票券上鏈系統 TECH-SPEC
tags: [SPEC]

---

# 票券上鏈系統 TECH-SPEC

[TOC]


## DEMO 20191125

- [ ] 票種 IPFS 頁面 加上 tokenId
- [ ] 票種/票券 頁面設計


https://ipfs.io/ipfs/Qmbe52fqRi3hfKaP5Y8ukvX4ahPz9bL4yFrRKi5SJZGpXn/?sn=0000000004

{%pdf https://ipfs.globalupload.io/QmRVLbd2cRAh1UCEdd9efD2EWwYSEafzJUbark3rdsqdq7 %}

## SECURITY

* IP Whilte List
* GCP
* Transaction Records
* AWS http://akuma1.pixnet.net/blog/post/316094659-%EF%BC%88%E5%85%AB%EF%BC%89vpc%E8%88%87nat-gateway%EF%BC%8D%EF%BC%8Daws%E7%B6%93%E9%A9%97%E6%95%99%E5%AD%B8
* Transfer ownership Contract
* https://bitcoin.stackexchange.com/questions/57020/how-to-securely-store-bitcoin-server-side

## V3

### 架構

{%pdf https://ipfs.globalupload.io/QmWaXsuV9GomYEw61Mpjy5q3FhHWtSPDwYgXzQx9vVUbb9 %}

### 試算

{%pdf https://ipfs.globalupload.io/QmSLiPxaus9JWf9JBL6Kspv2LSs53oVFZv5GKFQrvPHHS4 %}

N: 總客戶數
M: 總券種數
每天更新 3 次

* 一次費用 = (1 + N) x $123.61 + M x $2.67
* 每月費用 = M x 3 x 30 x $0.46

例如 20 個客戶、100 種券：

* 一次費用 = (1 + 20) x $123.61 + 100 x $2.67 = NTD$2862.81 (平均一券種 <span style="color:red">$28.63</span>)
* 每月費用 = M x 3 x 30 x $0.46 = NTD$4140 (平均一券種 <span style="color:red">$41.4</span>)

## DIAGRAMS

### Architecture: System

{%pdf https://ipfs.globalupload.io/QmZ7nTBcmZSXQup3BDP4374n7CPCuZXx1tiu3rog9ScEKN %}


### Sequence: 建卷

* [->mermaid](https://tinyurl.com/y53c59ro)


```mermaid
sequenceDiagram

Note over Vendor, YFP: 建卷

rect rgb(229, 255, 204)
    Vendor ->> +YFP: 建卷
    YFP -->> -Vendor: ok
    YFP ->> +API: MintToken
    API ->> +IPFS: initial state
    IPFS -->> -API: hash
    API ->> +Ethereum: transaction(hash) $$
    
    Ethereum -->> -API: ok
    API -->> -YFP: ok
end

Note over Vendor, YFP: 驗證

    Vendor ->> +Ethereum: 查詢
    Ethereum -->> -IPFS: link

```

### Sequence: 特定票卷：購買/轉贈/核銷/作廢

* [-> mermaid](https://tinyurl.com/yycxbwm7)


```mermaid
sequenceDiagram

Note over User, Vendor: 特定票卷：購買/轉贈/核銷/作廢

rect rgb(229, 255, 204)
    User ->> +YFP: 購買
    YFP -->> -User : ok
    User ->> +YFP: 轉贈
    YFP -->> -User : ok
    User ->> +YFP: 核銷
    YFP -->> -User : ok
    Vendor ->> +YFP: 作廢
     YFP -->> -Vendor: ok
    YFP ->> +API: SetTokenState
    API ->> +IPFS: new state
    IPFS -->> -API: hash
    API ->> +Ethereum: transaction(hash) $$

    Ethereum -->> -API: ok
    API -->> -YFP: ok
end

    Note over User, Vendor: 驗證

    User --> +Ethereum: 查詢
    Ethereum -->> -IPFS: link
    Vendor ->> +Ethereum: 查詢
    Ethereum -->> -IPFS: link
```
### Info Hierarchy

* [--> mermaid](https://tinyurl.com/ramjeec)

```mermaid
graph LR

A[CONTRACT<br> Matrix:ERC721] -->|mint| B1(票卷 Token:0)
B1 --> C1{*}
C1 --> D11[Info]
D11 --> F11[ 田馥甄 2019 演唱會 <br> ...]
C1 --> D12[State]
D12 -->|IPFS| F1[fa:fa-lock sn &nbsp sold ...<br> 0000 11/11 <br> 0001 11/23 <br> 0002 11/23 <br> ...]

A[CONTRACT<br> Matrix:ERC721] -->|mint| B2(票卷 Token:1)
B2 --> C2{*}
C2 --> D21[Info]
D21 --> F21[ 田馥甄 2020 演唱會 <br> ...]
C2--> D22[State]
D22 -->|IPFS| F2[fa:fa-lock sn &nbsp sold ...<br> 0000 11/11 <br> 0001 11/23 <br> 0002 11/23 <br> ...]

    style A fill:#f9f,stroke:#333,stroke-width:4px
```

## COST

### Ethereum

* https://ropsten.etherscan.io/address/0xc3f50159680c5bfec5946a7bc9a7c62a8e933ce3

![](https://i.imgur.com/rSr9hRz.png)

### IPFS

(pinata)
![](https://i.imgur.com/2fW6utl.png)

每個月約
* `400 * 1000 * 3 * 30 / 1000000000 = 0.036 GB`
* `0.15 * 30 * 0.036 = 0.162 NTD`

###### tags: `SPEC`
