Understanding XRP Ledger with pseudocode

in #ripple7 years ago (edited)

Hi, I'm a software engineer.
This is my best pseudocode to understand XRP Ledger.
See Developer Center & Portal on Ripple for detail.

Thanks!

// Trivial details for me are omitted.
// Let me know if you found any mistakes.

class OurRealWorld
    // Users of XRP Ledger
    // Such as: mobile/web wallets, gateways to financial institutions, trading platforms... 
    Client[]

    // Validators of user's transactions. Major implementation is rippled.
    // Handle client's requests
    Validator[]

    // Do read-only access to XRP Ledger.
    // Handle client's requests
    TrackingNode[]

class Client
    // Key : base58check([33] ++ (any 128bit binary))
    fun SendTransaction(Transaction, Key[])
    fun GetTransactionResult(TransactionHash)
    fun GetAccountInfo(Account)

class Validator
    // Contains all validated transactions, account balance, ....
    // Represents all XRP Ledger histories.
    // Corresponds to blocks in Bitcoin.
    // All validators have the same validated ledgers.
    // A new validated ledger is to be added to the end of list in every several seconds.
    Ledger[] ledgers

    // Should be "trusted" not to collude in an attempt to defraud. (Important!)
    UniqueNodeList peers

    fun DoConsensusRound()
        Receive transactions via endpoint
        Validate transactions
        Create new Ledger from validated transactions
        Send new ledger to other peers
        If certain percent of peers say OK
            The ledger is valid. Add it to ledgers.

    fun TheMainLoop()
        do parallel while true
            Process API requests from clients
            DoConsensusRound()

class TrackingNode
    // Same as Validator except for not doing validation.


////////////
// DETAIL
////////////


// Modifier of ledger
class Transaction
    Variant of
        AccountSet // Account operations
        Payment
        EscrowCancel // Escrow operations
        EscrowCreate
        EscrowFinish
        OfferCancel // Offer operations
        OfferCreate
        PaymentChannelClaim // PaymentChannel operations
        PaymentChannelCreate
        PaymentChannelFund
        SetRegularKey
        SignerListSet
        TrustSet

// Transactions and partial ledger states modified by them.
class Ledger
    Header
        parent_hash // hash of previous ledger
        closed // If true, this ledger is valid.
    Transaction[]
    LedgerNode[] ledgerState

// Partial state of XRP Ledger.
class LedgerNode
    Variant of
        AccountRoot
        DirectoryNode
        Escrow
        Offer
        PayChannel
        RippleState
        SingnerList

// Account state
class AccountRoot
    Account // Example: rJTxo758PPKuu7cYzYfTpHtyJiReMYotz4
    Balance // in XRP
    RegularKey
    Flags // password, trust line, payment settings

// Grouper of state
class DirectoryNode
    Variant of
        OwnerDirectories // RippleState, Offer nodes of an owner
        OfferDirectories // exchange orders

// Escrow ... mechanism of payment when some conditions fulfilled.
class Escrow
    Account
    Destination
    Amount
    Condition

// Offer state
class Offer
    Account
    TakerPays
    TakerGets

// Payment channel state
class PayChannel
    Account
    Destination
    Amount
    Balance

// Trust lines state between 2 accounts
class RippleState
    Balance // IOU from the low account view
    High/LowLimit // Position limit of IOU

// Multi-signing state
class SingnerList
    SignerQuorum
    SignerEntry[]

class SignerEntry
    Account
    SignerWeight

Sort:  

Welcome to Steemit!

We have all been waiting for you, we are glad you could make it.
I have given you a upvote to help you out!

Hope you love Steemit as much as we do.

Give these a read:

Chat with us:

If this post was helpful, please leave an upvote. It helps me to keep helping new users.

I'm sunnybooster, a booster for accounts not posts. Send me 0.5 STEEM or SBD to get a week of upvotes! If you don't yet know what this is its fine.

I am a bot and this was automated. I exist to help out new members and attempt to get them hooked

Congratulations @tabibito567! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.033
BTC 63464.16
ETH 3111.33
USDT 1.00
SBD 3.98