Skip to content

Commit dab0a50

Browse files
committed
Pages: Created Genesis Block and Address pages.
1 parent f7e02dd commit dab0a50

File tree

5 files changed

+130
-4
lines changed

5 files changed

+130
-4
lines changed

swift-polaris-playground.playground/Pages/Exploring the Dag.xcplaygroundpage/Contents.swift

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,55 @@
1-
//: [Previous](@previous)
1+
/*:
2+
# Exploring the Dag
3+
4+
To enable easy and efficient verification, the Polaris ledger is kept public and open. Since transactions on Polaris don't have fees, endless information can be stored on the network. Being able to traverse and analyze this information is key to the effective usage of the network.
5+
6+
## The Dag API
7+
8+
In addition to several other APIs, Swift-Polaris also provides a useful DAG API, that of which contains several methods for traversing, filtering, and querying through the dag.
9+
10+
To get started, let's initialize an instance of the Swift-Polaris API.
11+
*/
212

313
import Foundation
14+
import PlaygroundSupport
15+
import UIKit
416

5-
var str = "Hello, playground"
17+
var api: API // Init API instance buffer
18+
19+
API.Offline = API.Offline // Just a reminder to set to true for offline capability (make sure to run run_polaris.sh [node needs to be up!])
20+
21+
if API.Offline { // Check is offline
22+
api = API(apiURI: "https://localhost:8000") // Initialize API instance
23+
} else {
24+
api = API(apiURI: "https://108.41.124.60:8000") // Initialize API instance
25+
}
26+
27+
/*:
28+
## GetBestTransaction
29+
30+
The GetBestTransaction() method is key to the proper function of the Polaris network. Without it, the network would never reach consensus. In our case, GetBestTransaction() should give us the hash of the transaction you published in [Publishing Transactions](Publishing%20Transactions).
31+
*/
32+
33+
let baseView = DemoView(frame: CGRect(x: 0, y: 0, width: 500, height: 500)) // Bg
34+
35+
let bestTransactionHash = api.Dag.GetBestTransaction().0!["message"] as! String // Get best transaction
36+
37+
print("found best transaction with hash \(bestTransactionHash)") // Log best tx
38+
39+
baseView.Say(s: "🔎 found best transaction \(String(bestTransactionHash.prefix(8)) + "...")") // Display best tx
40+
41+
PlaygroundPage.current.liveView = baseView // Set live view
42+
PlaygroundPage.current.needsIndefiniteExecution = true // Keep
43+
44+
/*:
45+
* Experiment:
46+
Try [making another transaction](Publishing%20Transactions)!
47+
- Check back with the assistant editor and see if the best transaction hash has changed. 🕵️‍♀️🤫
48+
*/
49+
50+
/*:
51+
## Genesis Block
52+
53+
Although Polaris doesn't have blocks per say, Polaris still has a genesis. In the [next activity](Genesis%20Block), we'll see what the genesis is and what it does.
54+
*/
655

7-
//: [Next](@next)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*:
2+
# Genesis Address
3+
4+
To find the genesis address, let's initialize a new Swift-Polaris instance.
5+
*/
6+
7+
import Foundation
8+
import PlaygroundSupport
9+
import UIKit
10+
11+
var api: API // Init API instance buffer
12+
13+
API.Offline = API.Offline // Just a reminder to set to true for offline capability (make sure to run run_polaris.sh [node needs to be up!])
14+
15+
if API.Offline { // Check is offline
16+
api = API(apiURI: "https://localhost:8000") // Initialize API instance
17+
} else {
18+
api = API(apiURI: "https://108.41.124.60:8000") // Initialize API instance
19+
}
20+
21+
/*:
22+
As we've found earlier, the dag API can help us analyze data on the ledger. As a party of "data analysis", we can calculate the balance of a particular address. Let's do it with the genesis.
23+
*/
24+
25+
let baseView = DemoView(frame: CGRect(x: 0, y: 0, width: 500, height: 500)) // Bg
26+
27+
let genesisBalance = api.Dag.CalculateAddressBalance(address: "e3891ace0bce06b4acaddcbe47afecdbdcae1fb6").0!["message"] as! String // Get genesis transaction hash
28+
29+
print("found genesis balance \(genesisBalance)") // Log genesis
30+
31+
baseView.Say(s: "💸 found genesis balance: \(genesisBalance)") // Display found balance
32+
33+
PlaygroundPage.current.liveView = baseView // Set live view
34+
PlaygroundPage.current.needsIndefiniteExecution = true // Keep
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*:
2+
# Genesis Block
3+
4+
Unlike many other cryptocurrencies, Polaris does not have a genesis block, as it does not have blocks. Polaris does, however, have a genesis transaction set.
5+
6+
## Finding the Genesis
7+
8+
Let's try using the skills we learned in the last excercise to find the genesis transaction set, and see what it did to our dag. In this case, we'll make use of the Dag API by initializing a Swift-Polaris instance.
9+
*/
10+
11+
import Foundation
12+
import PlaygroundSupport
13+
import UIKit
14+
15+
var api: API // Init API instance buffer
16+
17+
API.Offline = API.Offline // Just a reminder to set to true for offline capability (make sure to run run_polaris.sh [node needs to be up!])
18+
19+
if API.Offline { // Check is offline
20+
api = API(apiURI: "https://localhost:8000") // Initialize API instance
21+
} else {
22+
api = API(apiURI: "https://108.41.124.60:8000") // Initialize API instance
23+
}
24+
25+
/*:
26+
In order to find the genesis transaction, we'll have to make use of something called the `alloc`. You might have noticed that the resources folder now contains a data/config folder (if you're running a private network). This folder contains a JSON file specifying an `alloc` telling go-polaris where to put the genesis supply. From this alloc, we can find the genesis transaction by querying dag transactions by recipient. To do so, we'll use api.Dag.GetTransactionsByAddress().
27+
*/
28+
29+
let baseView = DemoView(frame: CGRect(x: 0, y: 0, width: 500, height: 500)) // Bg
30+
31+
let genesisTransactionHash = api.Dag.GetTransactionsByAddress(address: "e3891ace0bce06b4acaddcbe47afecdbdcae1fb6").0!["message"] as! String // Get genesis transaction hash
32+
33+
print("found genesis \(genesisTransactionHash)") // Log genesis
34+
35+
baseView.Say(s: "😆🙌 found genesis \(String(genesisTransactionHash.prefix(12)) + "...")") // Display found genesis
36+
37+
PlaygroundPage.current.liveView = baseView // Set live view
38+
PlaygroundPage.current.needsIndefiniteExecution = true // Keep
39+
40+
/*:
41+
Now, we've found the genesis transaction, but what does it do? Simply put, the genesis transaction forces coins into a particular address without checking for validity. To find the balance of an address pertaining to the genesis, try the following activity: [Genesis Address](Genesis%20Address).
42+
*/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
mkdir data && mkdir data/config # Make data dir, config dir
2-
echo '{"alloc":{"e3891ace0bce06b4acaddcbe47afecdbdcae1fb6": 10}, "identifier": "main_net", "network": 0}' > data/config/config_main_net.json # Create Polaris monetary supply config
2+
echo '{"alloc":{"e3891ace0bce06b4acaddcbe47afecdbdcae1fb6": 100000}, "identifier": "main_net", "network": 0}' > data/config/config_main_net.json # Create Polaris monetary supply config
33
chmod +x ./go-polaris # Allow run
44
./go-polaris --network main_net --bootstrap-address localhost # Run polaris without an internet connection!

swift-polaris-playground.playground/contents.xcplayground

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
<page name='Hello, World'/>
66
<page name='Publishing Transactions'/>
77
<page name='Exploring the Dag'/>
8+
<page name='Genesis Block'/>
9+
<page name='Genesis Address'/>
810
</pages>
911
</playground>

0 commit comments

Comments
 (0)