Giter Site home page Giter Site logo

jstellarapi's Introduction

jStellarAPI

This library is an API for the Stellar network. It uses websocket to provide synchronous and asynchronous access. Currently requires eclipse to build.

This is very much a work in progress, contributions are welcomed.

Features

  • Pure Java implementation, from scratch
  • Websocket support, can subscribe to stellard events
  • Full binary read/write of the stellar wire format
  • Offline signing
  • HTTP REST support
  • Address generation
  • Uses Java futures for multi-threading ease

Quick start

How to send 10 STR to the JStellarAPI project, the simplest way possible.

File testWalletFile = new File("myUnEncryptedWallet.wallet");
StellarSeedAddress seed = new StellarSeedAddress("sXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
StellarWallet wallet = StellarWallet.createWallet(seed, testWalletFile);
wallet.sendSTR(BigInteger.TEN, new StellarAddress("gB2ZjFkenMnZLGZHEckAXn7xzTpn1omFti"));

jstellarapi's People

Contributors

pmarches avatar david290 avatar nybbs2003 avatar trzgwj avatar

Stargazers

Timothy Spann avatar Brandon Fish avatar Serge Simard avatar Iris Li avatar Chris Williams avatar Sunny Gonnabathula avatar MCAI avatar Michael avatar  avatar Zhongming Huang avatar Nicholas Dudfield avatar George Moschovitis avatar J avatar Matthew Fettig avatar Moe avatar

Watchers

Donovan Hide avatar Nicholas Dudfield avatar  avatar jargoman avatar  avatar  avatar

jstellarapi's Issues

currency wire format

BinarySerializer, write currency.

Your code is correct but ripple rejects "floating point" values whose mantissa doesn't have 16 digits.

Lets say I want to send the value 1.23.
Instead of the way you would expect.
mantissa = 123; // unscaled value
scale = 2; // or negative 2 in some implementations.

ripple expects it to be in wire format
mantissa = 1230000000000000;
scale = 15; // again may be -15

Both values are equal but only the second is accepted by rippled

1230000000000000 * 10 ^ -15 == 123 * 10 ^ -3; // statement is true

This is why the max and min scale have a difference of 16
80 - 96 = 16.
and is also why 54 bits is allocated for the mantissa
9999999999999999 // 54 bit number.

It took me three days to figure out why your code was correct but returning "invalid currency value"

Ripplebase58 decode

I have another one for you. Lines 58, 59 of Ripplebase58

Instead of...
byte[] tmp = new byte[bytes.length - (stripSignByte ? 1 : 0) + leadingZeros];
System.arraycopy(bytes, stripSignByte ? 1 : 0, tmp, leadingZeros, tmp.length - leadingZeros);

I believe they should be
byte[] tmp = new byte[bytes.length - (stripSignByte ? leadingZeros : 0)];
System.arraycopy(bytes, (stripSignByte ? leadingZeros : 0), tmp, 0, tmp.length - leadingZeros);

strip the s from seedaddress

In the README it says
RippleSeedAddress seed = new RippleSeedAddress("sXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

but I don't see anywhere in the code where the preceeding s is stripped from the seedaddress.

Shouldn't there be something along the lines of..
if (stringID = SEEDLENGTH + 1 && stringID[0] == 's') stripLeadingChar(stringID);

if (stringID.length!=SEEDLENGTH) throw exception("Invalid seed address length");

Great code by the way. I ported it to c#. I'll be testing my code soon :)

Unable to sign transactions locally.

I got the master version jstellarAPI java code , and create a private key and public key, then I want to signed a wallet ,but has error

this is my test code
=========================Test code Begin===========================
StellarBinaryObject rbo = null;
try {
BigInteger iSTRAmount = new BigInteger("100");
String randomStr1 = "1234567890abcdefgqwertyuiopasdfg";
DenominatedIssuedCurrency amount = new DenominatedIssuedCurrency(iSTRAmount);
StellarSeedAddress seed1 = new StellarSeedAddress(randomStr1.getBytes());
StellarAddress payee = new StellarAddress("gnCLrAVyhjsLzQmudwzJycr84fCCHaigVJ");
int nextTransactionSequenceNumber = 10;
StellarPaymentTransaction tx = new StellarPaymentTransaction(seed1.getPublicStellarAddress(), payee, amount, nextTransactionSequenceNumber);
//TODO Compute the required fee from the server_info
tx.fee = new DenominatedIssuedCurrency(new BigInteger("10"));
rbo = tx.getBinaryObject();
rbo = new StellarSigner(seed1.getPrivateKey()).sign(rbo); // <----here is error occurs
}
catch (Exception e){
e.printStackTrace();
return;
}
byte[] signedTXBytes = new StellarBinarySerializer().writeBinaryObject(rbo).array();

=========================Test code end===========================

The error message is :
java.lang.IllegalArgumentException: Invalid point encoding 0x79
at org.bouncycastle.math.ec.ECCurve.decodePoint(Unknown Source)
at jstellarapi.core.StellarPublicKey.getPublicPoint(StellarPublicKey.java:39)
at jstellarapi.keys.StellarSigner.sign(StellarSigner.java:39)
at jstellarapi.cli.JStellarCliMain.main(JStellarCliMain.java:71)

pls help me , what is wrong in my java code? thank you!

I think I finally got one lol

RippleBinarySerializer method readAmount line 129
You forgot to add the sign to BigDecimal fractionalValue
BigInteger biMagnitude = BigInteger.valueOf(longMagnitude);
should be...
BigInteger biMagnitude = BigInteger.valueOf(longMagnitude * sign);

or if you'd rather
if (sign<0) {
fractionalValue.negate();
}

nice code

I'm porting your code, looks really good. Send me a pm on the ripple forum.
and If you are going to check for null after assigning a field
var something; // this is undefined
then later...
if (something!=null) return something; // you're checking an undefined field

You should declare it as null, or set it to null in the constructor
var something = null;
then later...
if (something!=null) return something;

Ledger API

ledger_entry
ledger_current
ledger_closed
ledger_selector

Maven setup

Add maven support for builds and library dependencies.

Memo Types

Just a heads up that Memos make use of the the array type, so you might have to implement the readArray and readObject deserialization functions if you want to read all possible transactions. If you do so, you get the added benefit of being able to parse TransactionMetadata in the form that it is received when directly connected to the peer network. Here's an AccountSet transaction example with a Memo included as well (this is what you get on the peer network, I've removed the ledgerheader prefix):

12000322000000002400000E48201B0054625068400000000000000C732102EEAF2C95B668D411FC490746C52071514F6D3A7B742D91D82CB591B5443D1C5974473045022100F3B0747B1D0CD2C1DC25D172E5BD8359FBD9C50C34A405EAD3834AD83311A1E8022056CD3DCA12EA95B5AC9F21B705B32FA7A7E86AB7ED6DE95F7901EDCB7E6BDF3B811466B05AAE728123957EF8411C44B787650C27231DF9EA7C0964616E6E792E6A70677DC39F26F91CA2138F5D4E749C52AED1D15D0709FCC22298B6386FD4AC52C2D323DDD0EE7C2506DE07482B4715333954B9C8BF304EFB2BB721C9E378FC611E43D63980F41B07DEB64EC09717A319BA469867705797DB43FBF3FFB978000D1E600321C51C76C71D9F4F071EB48EA68A13BBCEEA55D059DEAF52355E80BB5ED21D8A2B70AD49E2FF9F66BCF21BD0C651EBC03ABED3E99418B12E2ADD5C42D00E3859D03656DE662ACD0D9456CB4CAFBA208EEBFB2F76D96C138E59C76CF96395C1C0D5A04D68397F81BA9303042F121F7B765F65E1C721CC4F23FC8DC3A2E66A25B6D7CB2649EF556B80FEBCE586A75138A90472698BFE5892A5C7940DCF59B3392E291823CAAF82C451507EF3040739874B4B0DD3B55CD1C12C9FD869E3DD08B835430BF0766FD583FD083372461FD8015776DEEF9879EEF633C03C644F08F2EED7514C917905468ED122D40978BD9FB76156DA52B6A3ECFD47902D572A4E15C7FB2F51708693EC9EBBFDF78BDA1B894884C70691580D2B32E9E17F5E912AA704D95AD046941CF73D96370B9CCA338D55565EA9AF417A1B248FA6C7C531051FD96C38FDBE212EFAEC74F993EFFB73648A4EBB4C16B2389B94C5C8684388243162C96E87909BC2D56654A93D7AFAA91ECCD876BE5DBEC987D01C237E861AFCBAB6B821A7AD3AF22CA2BC60E97164AC0FB5A16E56447C4541BEEED84FFC77F0AF224A1756C07E9ABC6E59C93AC7E450316F13DD525034D2B5C1598247BBD21629A28A157F773ADF0199C2D2AF358225E18C5E3D47E171548A2B0DEE0BCA2BDBE03B78CC506E6FF87EEE1FEFE4A67A614B7E1FF2ECFA9697511EA7F196BAA122A0CC27BC4415FA6959EC915191AC7200C690D1BCB74F27559804278CF449B2D3D1E0C5001C6A46F2873840D37FD1E4E93CC55D507748B5D2EEBB2FAED04BD8826D065C6045C59696F14E6583128F1B258F6599539B72C64C7CFAFF7E173071499A8A3337872BF2B68CF373795435BD98BD45383F71BF778ED193566B90BC6F05C6C3E2B2D2F1308EB121E4670D7E0872706CC76F54666B92FE18F4F1C44AFC339A04F7E99710802DE87948F2EB06F38E6DE93073A354D78D8370E5C8E29106C9B67F1B03591A459A9F278E5950DFAC933E9E2EA78F51D7A48455293C5DC722BE2CA0EB5B34FDA8970CD7161B63997A13F3AAD59B1EED0BA14B7F56DDBB178D06954488BBE8E1F1

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.