Событие от Wallet Service (TOPUP)
Принимает входящие on-chain события. Сейчас обрабатывается только TOPUP. БЕЗ auth/подписи (демо; в проде добавим HMAC). Валидация тела — вручную внутри handler'а (внешний контракт, строгая схема не навязывается).
Токен резолвится из реестра по contract address (приоритет) или по коду (fallback с warning'ом); незнакомый токен игнорируется.
Зачисление — ledger-проводка topup атомарным batch'ем: address:available ← vault:external. Для основного токена адреса баланс берётся из ledger; для «неосновного» (asset_mismatch) средства учитываются на отдельном ledger-счёте и видны в GET /vaults/{code}/balances.
Идемпотентность: unique(network, txHash) и unique(webhookEventId) — дубликат вернёт 200 {duplicate: true}. TRX-события и незнакомые адреса игнорируются (200 {ignored: true}).
curl -X POST "https://policy-engine-rest.ezig.workers.dev/webhooks/wallet" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
"tx": {
"network": "TRON",
"asset": "USDT",
"contract": "example_string",
"type": "example_string",
"id": "example_string",
"block": 42,
"timestamp": 3.14,
"from": "example_string",
"to": "example_string",
"value": "example_string"
}
}'
import requests
import json
url = "https://policy-engine-rest.ezig.workers.dev/webhooks/wallet"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_TOKEN"
}
data = {
"tx": {
"network": "TRON",
"asset": "USDT",
"contract": "example_string",
"type": "example_string",
"id": "example_string",
"block": 42,
"timestamp": 3.14,
"from": "example_string",
"to": "example_string",
"value": "example_string"
}
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
const response = await fetch("https://policy-engine-rest.ezig.workers.dev/webhooks/wallet", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_TOKEN"
},
body: JSON.stringify({
"tx": {
"network": "TRON",
"asset": "USDT",
"contract": "example_string",
"type": "example_string",
"id": "example_string",
"block": 42,
"timestamp": 3.14,
"from": "example_string",
"to": "example_string",
"value": "example_string"
}
})
});
const data = await response.json();
console.log(data);
package main
import (
"fmt"
"net/http"
"bytes"
"encoding/json"
)
func main() {
data := []byte(`{
"tx": {
"network": "TRON",
"asset": "USDT",
"contract": "example_string",
"type": "example_string",
"id": "example_string",
"block": 42,
"timestamp": 3.14,
"from": "example_string",
"to": "example_string",
"value": "example_string"
}
}`)
req, err := http.NewRequest("POST", "https://policy-engine-rest.ezig.workers.dev/webhooks/wallet", bytes.NewBuffer(data))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer YOUR_API_TOKEN")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("Response Status:", resp.Status)
}
require 'net/http'
require 'json'
uri = URI('https://policy-engine-rest.ezig.workers.dev/webhooks/wallet')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/json'
request['Authorization'] = 'Bearer YOUR_API_TOKEN'
request.body = '{
"tx": {
"network": "TRON",
"asset": "USDT",
"contract": "example_string",
"type": "example_string",
"id": "example_string",
"block": 42,
"timestamp": 3.14,
"from": "example_string",
"to": "example_string",
"value": "example_string"
}
}'
response = http.request(request)
puts response.body
{
"ok": true,
"incomingId": "example_string",
"balanceUpdated": true,
"newBalance": "example_string"
}
{
"ok": true,
"incomingId": "example_string",
"balanceUpdated": true,
"reason": "example_string",
"ledgerRecorded": true,
"addressAsset": "123 Main St",
"receivedAsset": "example_string"
}
{
"ignored": true,
"reason": "trx_events_disabled"
}
{
"duplicate": true,
"eventId": "example_string"
}
{
"error": "Bad Request",
"message": "The request contains invalid parameters or malformed data",
"code": 400,
"details": [
{
"field": "email",
"message": "Invalid email format"
}
]
}
{
"error": "Internal Server Error",
"message": "An unexpected error occurred on the server",
"code": 500,
"requestId": "req_1234567890"
}
/webhooks/wallet
Target server for requests. Edit to use your own host.
better-auth session token. Мобилка/сервисы. Веб использует cookie.
API key (sent in cookie)
The media type of the request body
Request Preview
Response
Response will appear here after sending the request
Authentication
Bearer token. better-auth session token. Мобилка/сервисы. Веб использует cookie.
API Key for authentication. Provide your API key in the cookie.