public void AdvanceTo(BuilderState next) { if(!CanAdvanceTo(next)) throw new InvalidOperationException("Can't move from state " + _state.ToString() + " to state " + next.ToString() + "."); BuilderState before = _state; _state = next; OnAfterAdvance(before, next, before != BuilderState.Idle, before != BuilderState.Idle && before != BuilderState.System); }
public DLCTransactionBuilder GetBuilder(Network network) { if (BuilderState is null) { throw new InvalidOperationException("The builder is not created yet"); } return(new DLCTransactionBuilder(BuilderState.ToString(), network)); }
public void AdvanceTo(BuilderState next) { if (!CanAdvanceTo(next)) { throw new InvalidOperationException("Can't move from state " + _state.ToString() + " to state " + next.ToString() + "."); } BuilderState before = _state; _state = next; OnAfterAdvance(before, next, before != BuilderState.Idle, before != BuilderState.Idle && before != BuilderState.System); }
protected override void OnAfterAdvance(BuilderState before, BuilderState after, bool wasInsideSystem, bool wasInsideGroup) { if(after != before) { if(wasInsideGroup) _writer.WriteEndElement(); if(after == BuilderState.Idle) _writer.WriteEndElement(); else _writer.WriteStartElement(after.ToString(), Context.YttriumNamespace); } }
public DLCNextStep GetNextStep(Network network) { if (BuilderState is null) { throw new InvalidOperationException("BuilderState not set"); } var builder = new DLCTransactionBuilder(BuilderState.ToString(), network); DLCNextStep nextStep; if (builder.State.IsInitiator) { if (FundKeyPath is null) { nextStep = DLCNextStep.Setup; } else if (Accept is null) { nextStep = DLCNextStep.CheckSigs; } else if (Sign is null) { nextStep = DLCNextStep.Fund; } else { nextStep = DLCNextStep.Done; } } else { if (builder.State.Funding is null) { nextStep = DLCNextStep.Setup; } else if (Sign is null) { nextStep = DLCNextStep.CheckSigs; } else if (!builder.State.Funding.PSBT.CanExtractTransaction()) { nextStep = DLCNextStep.Fund; } else { nextStep = DLCNextStep.Done; } } return(nextStep); }
protected override void OnAfterAdvance(BuilderState before, BuilderState after, bool wasInsideSystem, bool wasInsideGroup) { if (after != before) { if (wasInsideGroup) { _writer.WriteEndElement(); } if (after == BuilderState.Idle) { _writer.WriteEndElement(); } else { _writer.WriteStartElement(after.ToString(), Config.YttriumNamespace); } } }