Lightning Quick Draw Game With HOLD Invoices

How HOLD invoices work

Example Quick Draw Game

Development (warning! boring technical details ahead)

Game

Wallet

make tags="invoicesrpc"
lncli addholdinvoice <hash> --amt <amt>
lncli cancelinvoice <hash>
lncli settleinvoice <preimage>
lncli lookupinvoice <hash>

Game

void createInvoice()
{
using (RandomNumberGenerator rng = new RNGCryptoServiceProvider())
{
byte[] preimage = new byte[32];
rng.GetBytes(preimage);


myPreimage = BitConverter.ToString(preimage).Replace("-", string.Empty);
// Create a SHA256
using (SHA256 sha256Hash = SHA256.Create())
{
// ComputeHash - returns byte array
byte[] bytes = sha256Hash.ComputeHash(preimage);

// Convert byte array to a string
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
builder.Append(bytes[i].ToString("x2"));
}
myHash = builder.ToString();
Debug.Log("hash is "+ myHash);

shouldCheckIntent = true;
var req = "lightning:addholdinvoice?hash=" + myHash + "&amt=" + myBet + "&expiry=3600&message=" + myBet + "%20sat%20claimed%20by%20the%20Quick%20Draw%21&package=" + Application.identifier + "&allow_pay=" + myBet;

try
{
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageManager = currentActivity.Call<AndroidJavaObject>("getPackageManager");

AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
AndroidJavaObject uriData = uriClass.CallStatic<AndroidJavaObject>("parse", req);

AndroidJavaObject i = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", "com.indiesquare.pebble");

i.Call<AndroidJavaObject>("setAction", "android.intent.action.VIEW");
i.Call<AndroidJavaObject>("setData", uriData);

currentActivity.Call("startActivity", i);



}
catch (System.Exception e)
{
Debug.Log(e);
}
}
}


}

Caveats

make tags="invoicesrpc"

Moving Forward

How To Try The App

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

A Collection of 25 Awesome Python Scripts — Download PDF

SETS AND VENN DIAGRAM

Discord Price And Holder Bot For Solana Developer

Our Favorites From #OurSeason

Set Up Celery, Flower, and RabbitMQ for Airflow

How To Check If Your Windows 10 PC Supports Hyper-V Technology

5 Frontend tools to make your life easier

How to Fix Google Chrome Not Working With Symantec Endpoint

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mandel duck

Mandel duck

More from Medium

The Ultimate guide on how to acquire $DGH tokens.

PETZLAB.IO Community Update #1

CRYPTO SYZYGY : AMA Session With GEMS

Dragons Flame: Game Overview