Skip to content
Snippets Groups Projects
Select Git revision
  • e3b9c06bd17dfec668ce818d183b4abbffe746c3
  • master default protected
  • network/gtest-1000 protected
  • upgradable-multisig
  • runtime/gtest-1000
  • network/gdev-800 protected
  • cgeek/issue-297-cpu
  • gdev-800-tests
  • update-docker-compose-rpc-squid-names
  • fix-252
  • 1000i100-test
  • hugo/tmp-0.9.1
  • network/gdev-803 protected
  • hugo/endpoint-gossip
  • network/gdev-802 protected
  • hugo/distance-precompute
  • network/gdev-900 protected
  • tuxmain/anonymous-tx
  • debug/podman
  • hugo/195-doc
  • hugo/195-graphql-schema
  • gdev-900-0.10.1 protected
  • gdev-900-0.10.0 protected
  • gdev-900-0.9.2 protected
  • gdev-800-0.8.0 protected
  • gdev-900-0.9.1 protected
  • gdev-900-0.9.0 protected
  • gdev-803 protected
  • gdev-802 protected
  • runtime-801 protected
  • gdev-800 protected
  • runtime-800-bis protected
  • runtime-800 protected
  • runtime-800-backup protected
  • runtime-701 protected
  • runtime-700 protected
  • runtime-600 protected
  • runtime-500 protected
  • v0.4.1 protected
  • runtime-401 protected
  • v0.4.0 protected
41 results

launch-a-live-network.md

Blame
    • Hugo Trentesaux's avatar
      5d8ba754
      prepare gtest runtime (!171) · 5d8ba754
      Hugo Trentesaux authored
      * fix gtest runtime type name
      
      * add embeded client spec and genesis in binary
      
      (this re-buids chainspecs at each run)
      
      * refac chainspecs generation
      
      * add what is needed to build gtest chainspecs
      5d8ba754
      History
      prepare gtest runtime (!171)
      Hugo Trentesaux authored
      * fix gtest runtime type name
      
      * add embeded client spec and genesis in binary
      
      (this re-buids chainspecs at each run)
      
      * refac chainspecs generation
      
      * add what is needed to build gtest chainspecs
    send_membership.py 3.57 KiB
    """
    Copyright  2014-2021 Vincent Texier <vit@free.fr>
    
    DuniterPy is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    DuniterPy is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    """
    
    import getpass
    import urllib
    
    from duniterpy.api import bma
    from duniterpy.api.client import Client
    from duniterpy.documents import BlockUID, Membership
    from duniterpy.key import SigningKey
    
    # CONFIG #######################################
    
    # You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] [PATH]
    # or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
    # Here we use the secure BASIC_MERKLED_API (BMAS)
    BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443"
    
    
    ################################################
    
    
    def get_membership_document(
        membership_type: str,
        current_block: dict,
        identity: dict,
        key: SigningKey,
    ) -> Membership:
        """
        Get a Membership document
    
        :param membership_type: "IN" to ask for membership or "OUT" to cancel membership
        :param current_block: Current block data
        :param identity: identity card from /wot/lookup
        :param key: cryptographic key to sign documents
    
        :rtype: Membership
        """
    
        # get current block BlockStamp
        timestamp = BlockUID(current_block["number"], current_block["hash"])
    
        # get the uid and the timestamp of the corresponding identity
        uid = identity["uids"][0]["uid"]
        identity_timestamp = identity["uids"][0]["meta"]["timestamp"]
    
        # create membership document
        membership = Membership(
            version=10,
            currency=current_block["currency"],
            issuer=key.pubkey,
            membership_ts=timestamp,
            membership_type=membership_type,
            uid=uid,
            identity_ts=identity_timestamp,
        )
    
        # sign document
        membership.sign([key])
    
        return membership
    
    
    def send_membership():
        """
        Main code
        """
        # Create Client from endpoint string in Duniter format
        client = Client(BMAS_ENDPOINT)
    
        # Get the node summary infos by dedicated method (with json schema validation)
        response = client(bma.node.summary)
        print(response)
    
        # capture current block to get version and currency and blockstamp
        current_block = client(bma.blockchain.current)
    
        # prompt hidden user entry
        salt = getpass.getpass("Enter your passphrase (salt): ")
    
        # prompt hidden user entry
        password = getpass.getpass("Enter your password: ")
    
        # create key from credentials
        key = SigningKey.from_credentials(salt, password)
    
        # Look for identities on the network, take the first result since the
        # lookup was done with a pubkey, which should correspond to the first identity
        identities = client(bma.wot.lookup, key.pubkey)
        identity = identities["results"][0]
    
        # create a membership demand document
        membership = get_membership_document("IN", current_block, identity, key)
    
        # send the membership signed raw document to the node
        try:
            client(bma.blockchain.membership, membership.signed_raw())
        except urllib.error.HTTPError as e:
            print(f"Error while publishing membership: {e}")
    
    
    if __name__ == "__main__":
        send_membership()