public IEnumerator Process(Block block, BlockType blockType, Action <string> callback) { yield return(rpc.Process(block, NanoUtils.GetBlockTypeStr(blockType), (response) => { callback(JsonUtility.FromJson <ProcessResponse>(response).hash); })); }
// Only call this once... public void SetupFilteredConfirmationMessageWebsocketListener() { if (websocket != null) { AddFilteredConfirmationListener((websocketConfirmationResponseData) => { // Need to determine if it's: // 1 - Send to an account we are watching (we need to check pending, and fire off a loop to get these blocks (highest amount // first), if above a certain amount) // 2 - Send from an account we are watching (our balance goes down, check account_info) // 3 - Receive (pocket) an account we are watching (no need to check pending, but need to check balance. But this could be an old // block, so need to check account_info balance) // We could be monitoring multiple accounts which may be interacting with each other so need to check all if (websocketConfirmationResponseData.message.block.subtype.Equals(NanoUtils.GetBlockTypeStr(BlockType.send))) { var linkAsAccount = websocketConfirmationResponseData.message.block.link_as_account; if (watchers.ContainsKey(linkAsAccount)) { // Invoke callbacks foreach (var val in watchers[linkAsAccount]) { val.Value(new WatcherInfo(new NanoAmount(websocketConfirmationResponseData.message.amount), ConfType.SendTo, websocketConfirmationResponseData.message.hash)); } } var address = websocketConfirmationResponseData.message.block.account; if (watchers.ContainsKey(address)) { // Invoke callbacks foreach (var val in watchers[address]) { val.Value(new WatcherInfo(new NanoAmount(websocketConfirmationResponseData.message.amount), ConfType.SendFrom, websocketConfirmationResponseData.message.hash)); } } // Check for payment if (listeningPayment.callback != null) { if (listeningPayment.address.Equals(linkAsAccount) && listeningPayment.amount.Equals(new NanoAmount(websocketConfirmationResponseData.message.amount)) || (!listeningPayment.exactAmount && listeningPayment.amount > new NanoAmount(websocketConfirmationResponseData.message.amount))) { Unwatch(listeningPayment.address, listeningPayment.watcherId); listeningPayment.callback(false); listeningPayment.callback = null; } } // Check for payout if (listeningPayout.callback != null) { if (listeningPayout.address.Equals(address) && websocketConfirmationResponseData.message.block.balance.Equals("0")) { Unwatch(listeningPayout.address, listeningPayout.watcherId); listeningPayout.callback(false); listeningPayout.callback = null; } } } else if ((websocketConfirmationResponseData.message.block.subtype.Equals(NanoUtils.GetBlockTypeStr(BlockType.receive))) || (websocketConfirmationResponseData.message.block.subtype.Equals(NanoUtils.GetBlockTypeStr(BlockType.open)))) { var account = websocketConfirmationResponseData.message.account; if (watchers.ContainsKey(account)) { // Invoke callbacks foreach (var val in watchers[account]) { val.Value(new WatcherInfo(new NanoAmount(websocketConfirmationResponseData.message.amount), ConfType.Receive, websocketConfirmationResponseData.message.hash)); } } } if (blockListener.ContainsKey(websocketConfirmationResponseData.message.hash)) { blockListener[websocketConfirmationResponseData.message.hash](false, websocketConfirmationResponseData.message.hash); blockListener.Remove(websocketConfirmationResponseData.message.hash); } }); } else { Debug.Log("Websocket must be initialised before calling SetupConfirmationListener"); } }