This repo is to build the transaction monitor of Tonspay , Which able to monit the transactions onchain.
Tonspay monitor system including :
-
- moniting transactions onchain
- Verfiy invoice payment transactions
- supporting chains :
- TON
- Solana
- Arbitrum
- Goerli
- moniting transactions onchain
-
- Invoice payment confirmed call back .
- Https request
- Wss boardcast
- Invoice payment confirmed call back .
Tonspay payment function working on different logic due to the chain states .
-
User pay invoice with 2 transactions :
- Payment transaction :
- Directly from
User account
intoMerchant account
on chain .
- Directly from
- Notification transaction :
- From
User account
intonotification account
- Transaction comment :
Invoice ID
- From
Monitor logic :
- Monit the
notification account
for any transaction . - Read the comment of transaction to find the invoice .
- Verfiy invoice payment transaction match require or not .
- Payment transaction :
-
Same as SOLANA
-
Deploy
invoice-payment-contract
to recive payment .Contract including
transfer
&transferErc20
function :- Method :
- to . address
- amount . uint256
- token . address (option)
- Contract logic
- Recive token from
User account
- Culcuate
fee
&pay_amount
fromamount
- Send to
to
address withpay_amount
- Add a new
event
to record the invoice payment
- Recive token from
Monitor logic :
- Listen to the
event
of invoice payment
- Method :
Tonspay callback system support for both http
& websocket
. Merchant can set the callback path via Bot or Restful .
- Method :
POST
- Body : ${body}
-
Pre-listen subscript request :
- Send in json
{ "action" : "subscript", "merchanKey":"Your-merchant-api-kay" }
-
Payment callback :
- Recive in json : ${body}
The callback body will be sign by a keypair of Tonspay official to avoid callback interface being witch attack .
Body :
{
sign : "The signature data to prove message sended from tonspay"
}
The sign
are a signature that using ed25519
. Result being encode by base58
, please decode it into bytes by base58.
You will be able to deocde the signature-data by tweetnacl
into data ${base64-data}
.
Base64-data decode with json.parse
:
{
"uid":0, //Your merchant user id in telegram bot . Please verfiy if it is your callback.
"invoiceId":"",//Which invoice this callback for .
"paymentMethod":"",//The payment method of the invoice .
"confirmedBlock":"", //How many block since the callback confirm .
"paymentDetails":{
"from":"",//The address of payer .
"amount":0,//How much this transaction paid on chain .
"hash" : "",//The transaction hash of this payment .
},
"routerFeeDetails":{
"from":"",//The address of payer .
"amount":"",//How much being charged by payment router .
"hash" : "" , //The sub transaction of router fee .
"isPrepaid":bool, //If this transaction being prepaird by merchant by Token .
},
"createTime":0//The time of this callback .
},
Tonspay signature publick-key :
ENzsJ58Lmb6GMfMPhsTKm1AYaEoL5Z24r9RVPKaYLyJ6
Verfiy logic in js :
const signData = b58.decode(rawData.sign);
const decodeData = nacl.sign.open( signData, b58.decode('ENzsJ58Lmb6GMfMPhsTKm1AYaEoL5Z24r9RVPKaYLyJ6'))
const finalData = json.parse(
Buffer.from(decodeData).toString()
)
-
Get ready of
DB
&npm
-
npm install
-
npm run monitor