0
\$\begingroup\$

I recently read this article which runs through a very basic implementation of a blockchain for cryptocurrencies using Kotlin. For no real reason I decided to try and write an XML schema which defines the blockchain model in the article.

I have no experience with XML schemas, so I would love any feedback on it.

Here is my XSD file:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="blockChain">
    <xs:complexType>
      <xs:sequence>

        <xs:element name="block">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:int" name="index" default="0" />
              <xs:element type="xs:string" name="hash" default="" />
              <xs:element type="xs:string" name="previousHash" default="0" />
              <xs:element type="xs:dateTime" name="timeStamp" />
              <xs:element type="xs:int" name="nonce" default="0" />
              <xs:element type="xs:int" name="numTransactions" default="0" />
              <xs:element type="TransactionIndexList" name="transactions" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>

        <xs:element name="transaction">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="hash" default="" />
              <xs:element type="TransactionType" name="type" />
              <xs:element type="TransactionInputIndexList" name="inputs" />
              <xs:element type="TransactionOutputIndexList" name="outputs" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>

        <xs:element name="transactionInput">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="transactionId" default="" />
              <xs:element type="xs:int" name="outputIndex" default="0" />
              <xs:element type="xs:long" name="amount" default="0" />
              <xs:element type="LinkedList" name="unlockingScript"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>

        <xs:element name="transactionOutput">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:long" name="amount" />
              <xs:element type="LinkedList" name="lockingScript" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>

      </xs:sequence>
    </xs:complexType>
  </xs:element>

<xs:simpleType name="TransactionIndexList">
<xs:list itemType="xs:int" />
</xs:simpleType>

<xs:simpleType name="TransactionType" final="restriction">
  <xs:restriction base="xs:string">
    <xs:enumeration value="COIN_BASE" />
    <xs:enumeration value="FEE_TRANSACTION" />
    <xs:enumeration value="REGULAR" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="TransactionInputIndexList">
  <xs:list itemType="xs:int" />
</xs:simpleType>

<xs:simpleType name="TransactionOutputIndexList">
  <xs:list itemType="xs:int" />
</xs:simpleType>

<xs:complexType name="LinkedListItem">
  <xs:sequence>
    <xs:element type="xs:int" name="index" />
    <xs:element type="xs:string" name="data" />
  </xs:sequence>
</xs:complexType>

<xs:complexType name="LinkedList">
  <xs:sequence>
    <xs:element type="LinkedListItem" name="ListItem" minOccurs="0" maxOccurs="0" />
  </xs:sequence>
</xs:complexType>

</xs:schema>
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.