public async Task <ProtectedTaskflow <TransferTask> > CommitTransfer(TokenStore source, TokenStore destination, decimal transferAmount, string reference = null) { Trace($"Transfer {transferAmount} from {source} to {destination}"); // Prepare var task = new TransferTask { SourceID = source.AccountID, DestinationID = destination.AccountID, SourceManagerPublicKey = source.Manager.PublicKey.ToString(), NetworkFee = DefaultOperationFee, TransferAmount = transferAmount, Reference = reference, }; var flow = new ProtectedTaskflow <TransferTask>(task); try { Trace("Prepare Transfer"); flow.Task = task = await Connection.PrepareTransfer(task); } catch { flow.Update(TaskProgress.Failed); } if (flow.IsFailed) { return(flow); } // External Signing if (await Sign(task, source.Manager)) { try { // Submit Trace("Execute CreateContract"); flow.Task = await Connection.Transfer(task); flow.SetPending(this); } catch (Exception e) { Trace(e); flow.Update(TaskProgress.Failed); } } else { Trace("Sign cancelled"); flow.Update(TaskProgress.Cancelled); } return(flow); }
public async Task <ProtectedTaskflow <CreateContractTask> > CreateAccount(string name, Identity managerIdentity, TokenStore source, decimal transferAmount, string stereotype = null) { Trace($"Create Account '{name}' for {managerIdentity}, transferring {transferAmount} from {source}"); // Create Task and Flow var task = new CreateContractTask { Name = name, Stereotype = stereotype ?? Account.DefaultStereotype, ManagerID = managerIdentity.AccountID, SourceID = source.AccountID, SourceManagerPublicKey = managerIdentity.PublicKey.ToString(), NetworkFee = DefaultOperationFee, TransferAmount = transferAmount, }; var flow = new ProtectedTaskflow <CreateContractTask>(task); // Prepare Task try { Trace("Prepare CreateContract"); flow.Task = task = await Connection.PrepareCreateContract(task); } catch { flow.Update(TaskProgress.Failed); } if (flow.IsFailed) { return(flow); } // External Signing if (await Sign(task, source.Manager)) { try { // Submit Trace("Execute CreateContract"); flow.Task = await Connection.CreateContract(task); flow.SetPending(this); } catch (Exception e) { Trace(e); flow.Update(TaskProgress.Failed); } } else { Trace("Sign cancelled"); flow.Update(TaskProgress.Cancelled); } return(flow); }