Skip to content

Commit

Permalink
0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekn committed Feb 23, 2016
1 parent 2ed7891 commit 657c720
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'java'
apply plugin: 'ivy-publish'

sourceCompatibility = 1.6
version = '0.1.1'
version = '0.1.2'
group = 'stellar'

jar {
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/org/stellar/sdk/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ public Account(KeyPair keypair, Long sequenceNumber) {
mSequenceNumber = checkNotNull(sequenceNumber, "sequenceNumber cannot be null");
}

/**
* Returns keypair associated with this Account
*/
@Override
public KeyPair getKeypair() {
return mKeyPair;
}

/**
* Returns current sequence number ot this Account.
*/
@Override
public Long getSequenceNumber() {
return mSequenceNumber;
}

@Override
public Long getIncrementedSequenceNumber() {
return new Long(mSequenceNumber + 1);
}

/**
* Increments sequence number in this object by one.
*/
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/stellar/sdk/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ public Builder(TransactionBuilderAccount sourceAccount) {
mOperations = Collections.synchronizedList(new ArrayList<Operation>());
}

public int getOperationsCount() {
return mOperations.size();
}

/**
* Adds a new <a href="https://www.stellar.org/developers/learn/concepts/list-of-operations.html" target="_blank">operation</a> to this transaction.
* @param operation
Expand Down Expand Up @@ -217,8 +221,10 @@ public Builder addMemo(Memo memo) {
public Transaction build() {
Operation[] operations = new Operation[mOperations.size()];
operations = mOperations.toArray(operations);
Transaction transaction = new Transaction(mSourceAccount.getKeypair(), mSourceAccount.getIncrementedSequenceNumber(), operations, mMemo);
// Increment sequence number when there were no exceptions when creating a transaction
mSourceAccount.incrementSequenceNumber();
return new Transaction(mSourceAccount.getKeypair(), mSourceAccount.getSequenceNumber(), operations, mMemo);
return transaction;
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/stellar/sdk/TransactionBuilderAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public interface TransactionBuilderAccount {
*/
Long getSequenceNumber();

/**
* Returns sequence number incremented by one, but does not increment internal counter.
*/
Long getIncrementedSequenceNumber();

/**
* Increments sequence number in this object by one.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/stellar/sdk/responses/AccountResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public Long getSequenceNumber() {
return sequenceNumber;
}

@Override
public Long getIncrementedSequenceNumber() {
return new Long(sequenceNumber + 1);
}

@Override
public void incrementSequenceNumber() {
sequenceNumber++;
Expand Down
9 changes: 6 additions & 3 deletions src/test/java/org/stellar/sdk/ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ Transaction buildTransaction() throws IOException {
KeyPair destination = KeyPair.fromAccountId("GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR");

Account account = new Account(source, 2908908335136768L);
Transaction transaction = new Transaction.Builder(account)
Transaction.Builder builder = new Transaction.Builder(account)
.addOperation(new CreateAccountOperation.Builder(destination, "2000").build())
.addMemo(Memo.text("Hello world!"))
.build();
.addMemo(Memo.text("Hello world!"));

assertEquals(1, builder.getOperationsCount());
Transaction transaction = builder.build();
assertEquals(2908908335136769L, transaction.getSequenceNumber());
assertEquals(new Long(2908908335136769L), account.getSequenceNumber());
transaction.sign(source);
return transaction;
}
Expand Down

0 comments on commit 657c720

Please sign in to comment.