Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                ### Interaction

<script src="https://cdn.cosmic.plus/stellar-sdk@3.x"></script>
<script src="https://cdn.cosmic.plus/loopcall@1.x"></script>


<form>
  <fieldset>
    <legend>#pubkey</legend>
    <input type="text" id="pubkey" placeholder="Public key">
  </fieldset>
  
  <fieldset>
    <legend>#transfers</legend>
    <pre id="transfers"></pre>
  </fieldset>

</form>


### Description

This pen makes use of [stellar-sdk](https://stellar.github.io/js-stellar-sdk/) and [@cosmic-plus/loopcall](https://cosmic.plus/#view:js-loopcall) to implement a Lumen distribution explorer that has the genesis account for starting point.

### Concepts

- [Lumen distribution](https://www.stellar.org/foundation/programs): A process that used to have a [clear mandate](https://web.archive.org/web/20190429213554/https://www.stellar.org/about/mandate/).
- [Genesis account](https://stellar.stackexchange.com/a/1123/1351): The first Stellar account, initially holding all Lumens.

### Keypoints

- `GAAZI...CCWN7` is the genesis account. It received 100 billion Lumens at network creation.
- **#transfers** list outgoing payments worth at least one million Lumens.
- Click on **#transfers** destination pubkeys to follow the track.
- `loopcall()` fetches the operation history for **#pubkey** and passes it to `ingest()` on-the-fly.
- `ingest()` filters, formats and displays the records.
- When **#pubkey** changes, `breaker()` returns true & the previous `loopcall()` stops.


### Challenges

- **easy/** Edit this pen to add a **#previous** button that can go back one step at a time until the genesis account.
- **hard/** Edit this pen to let the user to define **#minAmount**, **#maxAmount**, and **#asset**.

_Give it a try by editing the code, and be the first to post a solution on GalacticTalk!_

### Documentation

- [@cosmic-plus/loopcall documentation](https://cosmic.plus/#view:js-loopcall)
- [stellar-sdk OperationCallBuilder documentation](https://stellar.github.io/js-stellar-sdk/OperationCallBuilder.html)
- ['Operations for Account' on Stellar laboratory](https://www.stellar.org/laboratory/#explorer?resource=operations&endpoint=for_account&values=eyJhY2NvdW50X2lkIjoiR0FBWkk0VENSM1RZNU9KSENUSkMyQTRRU1k2Q0pXSkg1SUFKVEdLSU4yRVI3TEJOVktPQ0NXTjcifQ%3D%3D&network=public)

### Social

- [Discuss that pen on GalacticTalk](https://galactictalk.org/d/2171-pen-of-the-week-loopcall-lumen-distribution-explorer)
              
            
!

CSS

              
                
              
            
!

JS

              
                // $ npm install stellar-sdk @cosmic-plus/loopcall
// const StellarSdk = require("stellar-sdk")
// const loopcall = require("@cosmic-plus/loopcall")
const $ = document.querySelector.bind(document)

/* Configuration */
const horizon = "https://horizon.stellar.org"
const server = new StellarSdk.Server(horizon)
const minAmount = 1000000

/* Core */
function iterateOperations (pubkey, filter, breaker)  {
  const callBuilder = server.operations().forAccount(pubkey)
  loopcall(callBuilder, { filter, breaker })
}

function matchRecord (record) {
  return record.type === "payment"
    && record.asset_type === "native"
    && record.from === $("#pubkey").value
    && record.amount >= minAmount
}

/* Interface */
function refresh (pubkey) {
  $("#pubkey").value = pubkey
  $("#transfers").innerHTML = ""
  const breaker = () => pubkey !== $("#pubkey").value
  iterateOperations(pubkey, processRecord, breaker)
}

function processRecord (record) {
  if (!matchRecord(record)) return
  
  const destination = makeLink(record.to)
  $("#transfers").appendChild(destination)
  
  const date = record.created_at.substr(0, 10)
  const amount = record.amount.split(".")[0]
  const text = ` | ${date} | ${amount}\n`
  const details = document.createTextNode(text)
  $("#transfers").appendChild(details)
}

function makeLink (pubkey) {
  const a = document.createElement("a")
  a.onclick = () => refresh(pubkey)
  a.textContent = pubkey.substr(0, 5) + "..." + pubkey.substr(-5)
  return a
}

/* Events */
$("#pubkey").oninput = () => refresh ($("#pubkey").value)

/* Init */
refresh("GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7")
              
            
!
999px

Console