public IEnumerator Send(string toAddress, NanoAmount amount, string privateKey, string work, Action <bool, string> callback) { // First we get the frontier NanoAmount currentBalance = null; string previous = null; string rep = defaultRep; string fromAddress = NanoUtils.PrivateKeyToAddress(privateKey); yield return(AccountInfo(fromAddress, (accountInfo) => { currentBalance = new NanoAmount(accountInfo.balance); previous = accountInfo.frontier; rep = accountInfo.representative; })); if (previous != null) { if (String.IsNullOrEmpty(work)) { // Generate the work yield return(WorkGenerate(fromAddress, previous, (workResponse) => { work = workResponse; })); } if (!String.IsNullOrEmpty(work)) { // Create the block to send var newBalance = currentBalance - amount; var block = CreateBlock(fromAddress, NanoUtils.HexStringToByteArray(privateKey), newBalance, NanoUtils.AddressToPublicKeyHexString(toAddress), previous, rep, work); yield return(Process(block, BlockType.send, (hash) => { if (hash != null) { callback(false, hash); } else { callback(true, ""); } Debug.Log(hash); })); } else { callback(true, ""); Debug.Log("Invalid work"); } } else { callback(true, ""); Debug.Log("No account exists to send from"); } }
public IEnumerator Receive(string address, PendingBlock pendingBlock, string privateKey, string work, Action <bool, string> callback) { // First we get the frontier NanoAmount currentBalance = null; string previous = null; var rep = defaultRep; yield return(AccountInfo(address, (accountInfo) => { currentBalance = new NanoAmount(accountInfo.balance); previous = accountInfo.frontier; if (previous != null) { rep = accountInfo.representative; } })); if (String.IsNullOrEmpty(work)) { // Generate the work yield return(WorkGenerate(address, previous, (workResponse) => { work = workResponse; })); } if (!String.IsNullOrEmpty(work)) { // Create the block to receive var newBalance = currentBalance + pendingBlock.amount; var block = CreateBlock(address, NanoUtils.HexStringToByteArray(privateKey), newBalance, pendingBlock.source, previous, rep, work); yield return(Process(block, previous == null ? BlockType.open : BlockType.receive, (hash) => { if (hash != null) { callback(false, hash); } else { callback(true, ""); } Debug.Log(hash); })); } else { callback(true, ""); } }