Code Monkey home page Code Monkey logo

icp-integration's Introduction

ICP-Integration

How to using vb.net & Bash Script to monitoring ICP Coin & ckBTC

Our team lacks proficiency in RUST, as well as Node.js and JavaScript. Instead, we accomplished integration using our familiar VB.NET and Bash scripts. If readers encounter similar issues, they can refer to the following approach. However, developers with expertise in RUST or Node.js are advised against using this method.

  <WebMethod()>
    Public Sub ICPGetTask()

        Dim gCnnPCE As SqlConnection
        gCnnPCE = New SqlConnection(ConnStr)
        Try
            gCnnPCE.Open()
            Dim str As String
            str = "SELECT TOP 1 * FROM TxReceiveCoin WHERE COIN = @COIN AND Status = 0 ORDER BY ID DESC"
            Dim cmd As New SqlCommand(str, gCnnPCE)
            cmd.Parameters.AddWithValue("@COIN", "ICP")
            Dim da As New SqlDataAdapter(cmd)
            Dim dt As New DataTable
            da.Fill(dt)

            If dt.Rows.Count = 0 Then
                Context.Response.Write("0")
            Else
                Context.Response.Write(dt.Rows(0).Item("Address").ToString)
            End If


        Catch ex As Exception
            WriteErrror("ICPGetTask", ex.Message)
        Finally
            gCnnPCE.Close()
            gCnnPCE.Dispose()
        End Try

    End Sub

We first create an API for TabbyPOS, which is responsible for receiving requests from POS machines and monitoring a specific ICP address. Once a new request is received, the API will respond with 1. When the Linux Ubuntu server receives this response, it executes the following commands to check the balance of the ICP address.

#!/bin/bash
while true; do
    response=$(curl [API URL]/ICPGetTask)
    if [ "$response" -eq 0 ]; then
       echo "Response is equal to 0"
    else
         # Run the command if response is not zero
        output=$(dfx ledger --network ic balance $(dfx ledger account-id --of-principal "$response"))
        encoded_output=$(urlencode "$output")
        api_url="[API URL]/ICPUpdateTask?Address=$response&Balance=$encoded_output"
        curl "$api_url"       
    fi
    # Sleep for 2 seconds
    sleep 2
done

Once we obtain the ICP amount for a specific address, we will check in the background whether the order has been successfully paid.

Due to security and confidentiality reasons, we have not disclosed the code for the function that determines whether the payment was successful.

demo

icp-integration's People

Contributors

leekohching avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.