sim-wire-watch.go (2178B)
1 package main 2 3 import ( 4 "encoding/base64" 5 "errors" 6 "fmt" 7 "strconv" 8 ) 9 10 type IncomingHistory struct { 11 IncomingTransactions []IncomingReserveTransaction `json:"incoming_transactions"` 12 CreditAccount string `json:"credit_account"` 13 } 14 15 // type RESERVE | https://docs.taler.net/core/api-bank-wire.html#tsref-type-IncomingReserveTransaction 16 type IncomingReserveTransaction struct { 17 Type string `json:"type"` 18 RowId int `json:"row_id"` 19 Date Timestamp `json:"date"` 20 Amount string `json:"amount"` 21 DebitAccount string `json:"debit_account"` 22 ReservePub EddsaPublicKey `json:"reserve_pub"` 23 } 24 25 func WireWatch(finish chan interface{}, kill chan error) { 26 27 var wirewatchLongPoll int 28 if CONFIG.DisableDelays { 29 wirewatchLongPoll = 3000 30 } else { 31 wirewatchLongPoll = CONFIG.ProviderBackendPaymentDelay + 32 CONFIG.TerminalAcceptCardDelay + 33 CONFIG.WalletScanQrDelay + 34 5000 // add some delay for operations 35 } 36 37 fmt.Println("WIRE-WATCH: long poll to c2ec for ", wirewatchLongPoll, "milliseconds") 38 39 var HISTORY_ENDPOINT = CONFIG.C2ecBaseUrl + "/taler-wire-gateway/history/incoming" 40 41 url := FormatUrl( 42 HISTORY_ENDPOINT, 43 map[string]string{}, 44 map[string]string{ 45 "delta": "1024", // this value is used by the wirewatch 46 "long_poll_ms": strconv.Itoa(wirewatchLongPoll), 47 }, 48 ) 49 fmt.Println("WIRE-WATCH: requesting status update for withdrawal", url) 50 response, status, err := HttpGet( 51 url, 52 map[string]string{"Authorization": WireGatewayAuth()}, 53 NewJsonCodec[IncomingHistory](), 54 ) 55 if err != nil { 56 kill <- err 57 return 58 } 59 if status != 200 { 60 kill <- errors.New("wire-watch could not retrieve transaction: " + strconv.Itoa(status)) 61 return 62 } 63 64 res := *response 65 for _, r := range res.IncomingTransactions { 66 fmt.Println("WIRE-WATCH: Incoming Reserve Transaction(", r.RowId, r.DebitAccount, r.Amount, r.ReservePub, ")") 67 } 68 69 close(kill) 70 finish <- nil 71 } 72 73 func WireGatewayAuth() string { 74 75 userAndPw := fmt.Sprintf("%s:%s", CONFIG.WireGatewayUsername, CONFIG.WireGatewayPassword) 76 return "Basic " + base64.StdEncoding.EncodeToString([]byte(userAndPw)) 77 78 }