private void ButtonLoad_Click(object sender, RoutedEventArgs e) { loadWalletDialog.ShowDialog(); if (loadWalletDialog.FileName == "") { return; } try { Nonce = null; var fileBytes = File.ReadAllBytes(loadWalletDialog.FileName); ActiveWallet = Wallet.FileDeserialize(Encoding.ASCII.GetString(fileBytes)); } catch { ActiveWallet = null; } double?balance = null; if (ActiveWallet != null) { balance = ConnectionJob.GetStandardBalance(httpProvider, ActiveWallet.PublicKey); } RefreshUi(Connected, balance); }
private void ButtonCreate_Click(object sender, RoutedEventArgs e) { ActiveWallet = new Wallet(); Nonce = null; File.WriteAllText(@"Wallets\" + HexConverter.ToPrefixString(ActiveWallet.PublicKey), ActiveWallet.FileSerialize()); RefreshUi(Connected, ConnectionJob.GetStandardBalance(httpProvider, ActiveWallet.PublicKey)); }
private void ButtonConnect_Click(object sender, RoutedEventArgs e) { var connected = ConnectionJob.Handshake(httpProvider); double?balance = null; if (ActiveWallet != null) { balance = ConnectionJob.GetStandardBalance(httpProvider, ActiveWallet.PublicKey); } RefreshUi(connected, balance); }
public MainWindow() { InitializeComponent(); listView.ItemsSource = log; ConnectionJob.mainWindow = this; if (!Directory.Exists("Data")) { Directory.CreateDirectory("Data"); } if (!Directory.Exists("Wallets")) { Directory.CreateDirectory("Wallets"); } loadWalletDialog = new OpenFileDialog(); loadWalletDialog.Title = "Load wallet"; buttonSend.IsEnabled = false; buttonMine.IsEnabled = false; ContactStream = new FileStream("Data\\contacts", FileMode.OpenOrCreate, FileAccess.ReadWrite); var jobs = new List <Tuple <Type, string> >() { new Tuple <Type, string>(typeof(ConnectionJob), everyMinuteCron), }; ScheduleJobs(jobs).Wait(); var connected = ConnectionJob.Handshake(httpProvider); RefreshUi(connected, null); }
private void buttonConnect_Click(object sender, RoutedEventArgs e) { var destination = HexConverter.ToBytes(textBoxDestination.Text); if (destination != null) { double ammountDouble; if (double.TryParse(textBoxAmmount.Text, out ammountDouble)) { double feeDouble; if (double.TryParse(textBoxFee.Text, out feeDouble)) { var balance = ConnectionJob.GetSmallUnitsBalance(httpProvider, SenderWallet.PublicKey); if (balance != null) { var ammount = GetSmallestUnits(ammountDouble); var fee = GetSmallestUnits(feeDouble); if (_nonce == null) { _nonce = httpProvider.PeerPost <string, uint>(HexConverter.ToPrefixString(SenderWallet.PublicKey), @"http://127.0.0.1:8125/transaction/count").Result; } else { _nonce = _nonce + 1; } if ((balance + fee - 1) > ammount) { var tx = new Transaction() { Ammount = ammount, Destination = ByteManipulator.TruncateMostSignificatZeroBytes(destination), Fee = fee, Network = new byte[] { 1 }, Nonce = _nonce.Value, Source = ByteManipulator.TruncateMostSignificatZeroBytes(SenderWallet.PublicKey) }; tx.Sign(SenderWallet.PrivateKey); var response = httpProvider.PeerPost <string, string>(HexConverter.ToPrefixString(tx.Serialize()), @"http://127.0.0.1:8125/transaction/relay").Result; if (response != "ok") { MessageBox.Show("Sending transaction failed", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else //insufficient balance { MessageBox.Show("Insufficient balance", "Error", MessageBoxButton.OK, MessageBoxImage.Information); } } else //could not fetch balance { MessageBox.Show("Could not fetch nonce", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else //invalid fee { MessageBox.Show("Invalid fee", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else //invalid ammount { MessageBox.Show("Invalid invalid ammount", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else //invalid destination { MessageBox.Show("Invalid invalid destination", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { //propose 2: con.pullCord could have more than one value? NO! there is ONLY one gap at a time! // //first agent move: if agent.moveDist == 0 (prune) && agent.headCord == headCon.len (imply agent.moveDist == 0) //agent input: headCord, tailCon, tailCord //agent in/out: headCon, headCord //agent output: moveDist //con input: headCon.len //con in/out: nextCon.EnterLen //con output: tailCon.pullCord, pullDist // //- agent.moveDist = nextCon.EnterLen //- agent.headCon = nextCon //- agent.headCord = 0 //- tailCon.pullCord = agent.tailCord //pullCord CREATE //- tailCon.pullDist = moveDist //- nextCon.EnterLen -= min(agent.len, moveDist) //EnterLen DECREASE! //pull: if agent.moveDist == 0 & headCon.pullDist > 0 & agent.headCord == headCon.pullCord(max one agent per con) //agent input: headCon, headCord, tailCon, tailCord, moveDist //agent output: moveDist //con input: len, pullCord, pullDist //con output: pullCord, pullDist // //- pull = min(headCon.pullDist, headCon.len - agent.headCord) //- agent.moveDist += pull //- if tailCon != headCon //- - headCon.pullCord = headCon.len //pullCord RESET //- - headCon.pullDist = 0 //- tailCon.pullCord = agent.tailCord //pullCord PROPAGATE //- tailCon.pullDist = pull //last agent move: one match per connection! no clash! //agent input: tailCon, tailCord, moveDist //con input: EnterLen, pullCord, pullDist, len //con output: EnterLen, pullCord, pullDist // //- if (agent.tailCord == tailCon.EnterLen) //last agent //- - move = min(tailCon.len - agent.tailCord, agent.moveDist) //- - tailCon.EnterLen += move //EnterLen INCREASE! //- - tailCon.pullCord += move //PullCord INCREASE! (until conLen) //- - tailCon.pullDist -= move //move forward: agent.moveDist > 0 //agent input: headCon, headCord, tailCon, tailCord, moveDist //agent output: headCord, tailCon, tailCord, moveDist //con input: speed, len //con output: none // //- speed = agent.headCon.speed //- move = min (speed, agent.moveDist) //moveDist is already not exceed con.len! //- move = min (move, tailCon.len - agent.tailCord) //lose speed artificially :( //could loop here for tailCord! //- agent.headCord += move //- agent.tailCord += move //- agent.moveDist -= move //- if (agent.tailCord == tailCon.len) tailCon = next(tailCon) //new propose //exitAgent = headCord == headCon.len: is a one-frame state! //bridgeAgent = headCon != tailCon: is a MULTI-FRAME state! => has a flag //these are 3 jobs, can't combine because of race-condition //every exitAgent: tailCon.pullForce = min(moveDist, tailCon.len - tailCord), life = 1 //every non-exit agent: agent.moveDist += headCon.pullForce, agent.pullFlag = true //propagate: every bridge agent with pullFlag: tailCon.pullForce = cap(agent.moveDist), life = 2, pullFlag = false //decrease all pullForce life, remove one with 0 life! //move all agent forward //when agent-head enter connection: con.EnterLen -= agent.Length (done) //when agent-head leave connection: start taking back part of agent.Length to connection //when agent-tail enter connection: begin partial-return process? //when agent-tail leave connection: assert(con.EnterLen not contains agent.Length) //heuristic: enterLen of connection "inside" an agent does not matter, it's not used by anyone: WRONG! it's used by intersection! //propose 1: //exit-agent: //- agent.force = min(nextCon.EnterLen, agent.tailLen) //- nextCon.EnterLen -= agent.len //- nextCon.queue.push(agent) //connection queue: //- if (queue[0].force > 0): queue[all - last].moveDist += force //- con.addComp(conForce = queue[0].force) //- queue[0].force = 0 //connection: all con with conForce //- queue[last].force = min(conForce, last.tailLen) //- con.removeComp(conForce) //moveForward //- consume moveDist to move headCord and tailCord //- if tailCord == tailLen: tailCon.queue.pop, tailCon.EnterLen = min(force, tailLen), tailCon = next(tailCon) //propose 2: //exit-agent //- agent.queue.add(nextCon) //- agent.force = min(nextCon.EnterLen, agent.tailLen) //- nextCon.EnterLen -= agent.len //pull connection: per agent //- if agent.force > 0 //- agent.queue[all].EnterLen += force //CLASH: because some con share agents! //propose 3: all adjustments are queued! //foreach(agent): //- exit-agent: headCord == headLen //- if targetCon == headCon: tailCon.pullQ = min(agent.Length, tailLen) //not clash with (B) //- else if nextCon.EnterLen > 0 //- - assert(moveDist == 0) //- - agent.headCon = nextCon; agent.headCord = 0; agent.moveDist = nextCon.EnterLen // (C) //- - nextCon.EnterLenQ -= agent.len //(A), not clash with (C) //- - tailCon.pullQ = min(moveDist, tailLen) //(B) //- non-exit-agent: //- - agent.moveDist += min(headCon.pull, headRoom) //avoid (B) //- - if bridge-agent: tailCon.pullQ = min(headCon.pull, tailLen) //not collide with (B) //- all-agent: moveDist > 0 //- - headCord += speed; tailCord += speed //- - if tailCross: nextTailCon.EnterLenQ = min(agent.moveDist, nextCon.len) //can't clash with (A) //foreach(con) //- con.pull = con.pullQ //- con.pullQ = 0 //this mean pull exist for 1 frame only! //- con.EnterLen = con.EnterLenQ + con.pull //- con.EnterLenQ = con.EnterLen var commandBuffer = _bufferSystem.CreateCommandBuffer().ToConcurrent(); var conLens = GetComponentDataFromEntity <ConnectionLengthInt>(); var connections = GetComponentDataFromEntity <Connection>(); var conTraffics = GetComponentDataFromEntity <ConnectionTraffic>(); var conSpeeds = GetComponentDataFromEntity <ConnectionSpeedInt>(); var indexes = GetComponentDataFromEntity <IndexInNetwork>(); var states = GetComponentDataFromEntity <ConnectionStateInt>(); var pulls = GetComponentDataFromEntity <ConnectionPullInt>(); var pullQs = GetComponentDataFromEntity <ConnectionPullQInt>(); var next = GetBufferFromEntity <NextBuffer>(); var agentJob = new AgentJob { CommandBuffer = commandBuffer, Connections = connections, ConLens = conLens, ConTraffics = conTraffics, Indexes = indexes, Next = next, ConSpeeds = conSpeeds, States = states, Pulls = pulls, PullQs = pullQs, NetGroups = GetComponentDataFromEntity <NetworkGroupState>(), NetInfos = GetComponentDataFromEntity <NetPathInfo>(), Exits = GetComponentDataFromEntity <Exit>(), Entrances = GetComponentDataFromEntity <Entrance>(), }.Schedule(this, inputDeps); var connectionJob = new ConnectionJob().Schedule(this, agentJob); connectionJob.Complete(); //for entity remove return(connectionJob); }