GithubHelp home page GithubHelp logo

pzpzpz / burstkit4j Goto Github PK

View Code? Open in Web Editor NEW

This project forked from signum-network/signumj

0.0 0.0 0.0 763 KB

Burstcoin Java Development Framework

License: Apache License 2.0

Java 100.00%

burstkit4j's Introduction

burstkit4j

Burstcoin Java Development Framework

Build Status

Beta Status

This project is currently in beta. Please report any issues through the GitHub issue tracker.

Including in your project

  • Maven:
<repositories>
	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>
</repositories>
<dependencies>
    <dependency>
	    <groupId>com.github.burst-apps-team</groupId>
	    <artifactId>burstkit4j</artifactId>
	    <version>v0.9-beta1</version>
	</dependency>
</dependencies>
  • Gradle:
repositories {
	maven { url 'https://jitpack.io' }
}
dependencies {
	implementation 'com.github.burst-apps-team:burstkit4j:v0.9-beta1'
}

Usage

  • Commonly used Burst objects / entities / helper classes can be found in the entity package.

  • For locally-performed cryptographic operations such as encrypting/decrypting, signing/verifying, etc please see the BurstCrypto interface (Use BurstCrypto.getInstance() to obtain a singleton instance)

  • For Burst Node API calls such as making transactions and looking at blocks/accounts/transactions, please see the BurstNodeService interface. (Use BurstNodeService.getInstance("http://nodeAddress.com:8125") to obtain an instance.)

The BurstNodeService wraps the returned values in RxJava Singles. You can create your own SchedulerAssigner to automatically make all returned values subscribe on the specified schedulers. If you don't want to use RxJava, call toFuture() on any Single.

GSON is used for JSON serialization/deserialization. To obtain a GsonBuilder customized to serialize/deserialize BurstKit entities, call BurstKitUtils.buildGson().

Examples

  • Sending a transaction containing an encrypted message
import burst.kit.burst.BurstCrypto;
import burst.kit.entity.BurstValue;
import burst.kit.entity.HexStringByteArray;
import burst.kit.entity.response.BRSError;
import burst.kit.entity.response.BroadcastTransactionResponse;
import burst.kit.service.BurstNodeService;
import io.reactivex.disposables.Disposable;

public class TransactionSender {
    /**
     * Example which sends 1 BURST to another account with a fee of 0.1 BURST
     * and includes an encrypted message which only the sender or recipient
     * can read. Performs all cryptographic functions (encrypting the message
     * and signing the transaction) offline so does not send the passphrase
     * to the node (which would be a huge security risk!)
     */
    public void sendTransactionWithEncryptedMessage() {
        // Obtain handles to services
        BurstCrypto burstCrypto = BurstCrypto.getInstance();
        BurstNodeService burstNodeService = BurstNodeService.getInstance("https://wallet.dev.burst-test.net");

        String passphrase = "passphrase"; // Your burst wallet passphrase
        byte[] recipientPublicKey = new HexStringByteArray("AABBCC112233").getBytes(); // Recipient public key

        // Generate the transaction without signing it
        Disposable disposable = burstNodeService.generateTransactionWithEncryptedMessage(burstCrypto.getBurstAddressFromPublic(recipientPublicKey), burstCrypto.getPublicKey(passphrase), BurstValue.fromBurst(1), BurstValue.fromBurst(0.1), 1440, burstCrypto.encryptTextMessage("Sent from burstkit4j!", passphrase, recipientPublicKey))
                .flatMap(response -> {
                    // Now we need to locally sign the transaction.
                    // Get the unsigned transaction bytes from the node's response
                    byte[] unsignedTransactionBytes = response.getUnsignedTransactionBytes().getBytes();
                    // Locally sign the transaction using our passphrase
                    byte[] signedTransactionBytes = burstCrypto.signTransaction(passphrase, unsignedTransactionBytes);
                    // Broadcast the transaction through the node, still not sending it any sensitive information. Use this as the result of the flatMap so we do not have to call subscribe() twice
                    return burstNodeService.broadcastTransaction(signedTransactionBytes);
                })
                .subscribe(this::onTransactionSent, this::handleError);
    }
    
    private void onTransactionSent(BroadcastTransactionResponse response) {
        // Get the transaction ID of the newly sent transaction!
        System.out.println("Transaction sent! Transaction ID: " + response.getTransactionID().getID());
    }
    
    private void handleError(Throwable t) {
        if (t instanceof BRSError) {
            System.out.println("Caught BRS Error: " + ((BRSError) t).getDescription());
        } else {
            t.printStackTrace();
        }
    }
}

burstkit4j's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar harryjph avatar jjos2372 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.