Skip to content

Commit

Permalink
More updates for 1.4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
fireduck64 committed Nov 16, 2020
1 parent 15ae69c commit d4978db
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 28 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Expand Up @@ -75,7 +75,7 @@ pinned_maven_install()
git_repository(
name = "snowblossom",
remote = "https://github.com/snowblossomcoin/snowblossom",
commit = "b17f71b69513ce386a47b03c98ea3380f2538f46",
commit = "4beebf0391ad492415fc257d06c2601f66ff2e24",
shallow_since = "1595994852 -0700"
)

Expand Down
4 changes: 4 additions & 0 deletions curl/addr.coins
@@ -0,0 +1,4 @@
curl -d '{"network_identifier": {"blockchain":"snowblossom","network":"testnet"}, "account_identifier":{"address":"snowtest:rg6hllwurpv5kxnpuncu6e4qrzycrjsg6vzukeac"} }' -H "Content-Type: application/json" http://localhost:8080/account/coins | jq .

echo ""

54 changes: 51 additions & 3 deletions src/main/java/io/swagger/controllers/Account.java
Expand Up @@ -30,16 +30,64 @@
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaInflectorServerCodegen", date = "2020-10-18T05:48:04.106Z[GMT]")
public class Account
{
public ResponseContext accountCoins(RequestContext request , AccountCoinsRequest body)
public ResponseContext accountCoins(RequestContext request , JsonNode body)
throws Exception
{
AccountCoinsRequest req = new ObjectMapper().readValue(body.toString(), AccountCoinsRequest.class);
NetworkIdentifier id = req.getNetworkIdentifier();
AccountIdentifier acct = req.getAccountIdentifier();

return new ResponseContext().status(Status.INTERNAL_SERVER_ERROR).entity( "Not implemented" );

}
ChainHash block_hash = null;
int block_idx;
SnowBlossomNode node = RoseSnow.getNode(id);

StubHolder stub_holder = RoseSnow.getClient(id);

if (block_hash == null)
{
BlockHeader head = node.getBlockIngestor().getHead().getHeader();
block_hash = new ChainHash( head.getSnowHash());

}
BlockHeader header = node.getDB().getBlockSummaryMap().get(block_hash.getBytes()).getHeader();

AddressSpecHash addr = new AddressSpecHash( acct.getAddress(), node.getParams());


List<TransactionBridge> bridges = GetUTXOUtil.getSpendableValidatedStatic(
addr,
stub_holder.getBlockingStub(),
header.getUtxoRootHash());


AccountCoinsResponse resp = new AccountCoinsResponse();
LinkedList<Coin> coins = new LinkedList<>();
for(TransactionBridge br : bridges)
{
Coin c = new Coin();
c.setAmount( RoseUtil.getSnowAmount( br.value, node.getParams() ));

ChainHash tx_out = new ChainHash(br.in.getSrcTxId());
int out_idx = br.in.getSrcTxOutIdx();

c.setCoinIdentifier( new CoinIdentifier().identifier( tx_out.toString() + ":" + out_idx));

coins.add(c);

}
if (req.isIncludeMempool())
{
// TODO include mempool

}
resp.setCoins(coins);
resp.setBlockIdentifier( new BlockIdentifier().hash(block_hash.toString()).index( (long) header.getBlockHeight()));

return new ResponseContext().entity(resp);
}


public ResponseContext accountBalance(RequestContext request , JsonNode body)
throws Exception
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/swagger/controllers/Block.java
Expand Up @@ -73,7 +73,7 @@ public ResponseContext block(RequestContext request , JsonNode body)

for( snowblossom.proto.Transaction s_tx : blk.getTransactionsList() )
{
b.getTransactions().add( RoseUtil.protoToModel(s_tx, node) );
b.getTransactions().add( RoseUtil.protoToModel(s_tx, node, node.getParams()) );
}


Expand All @@ -99,7 +99,7 @@ public ResponseContext blockTransaction(RequestContext request , JsonNode body )

BlockTransactionResponse resp = new BlockTransactionResponse();

resp.setTransaction( RoseUtil.protoToModel(s_tx, node) );
resp.setTransaction( RoseUtil.protoToModel(s_tx, node, node.getParams()) );

return new ResponseContext().entity( resp );
}
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/io/swagger/controllers/Construction.java
Expand Up @@ -139,10 +139,7 @@ public ResponseContext constructionParse(RequestContext request , JsonNode body)

NetworkIdentifier id = req.getNetworkIdentifier();

// TODO - this operation should not be online
SnowBlossomNode node = RoseSnow.getNode(id);

Transaction tx = RoseUtil.protoToModel(s_tx, node);
Transaction tx = RoseUtil.protoToModel(s_tx, null, params);

ConstructionParseResponse resp = new ConstructionParseResponse();
for(Operation op : tx.getOperations())
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/swagger/controllers/Mempool.java
Expand Up @@ -61,7 +61,7 @@ public ResponseContext mempoolTransaction(RequestContext request , JsonNode body
snowblossom.proto.Transaction s_tx = node.getMemPool().getTransaction(tx_id);
if (s_tx != null)
{
resp.setTransaction( RoseUtil.protoToModel(s_tx, node));
resp.setTransaction( RoseUtil.protoToModel(s_tx, node, node.getParams()));
}

return new ResponseContext().entity(resp);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/swagger/controllers/Network.java
Expand Up @@ -61,6 +61,7 @@ public ResponseContext networkOptions(RequestContext request , JsonNode body )
allow.getOperationStatuses().add(new OperationStatus().status("CONFIRMED").successful(true));
allow.getOperationStatuses().add(new OperationStatus().status("PENDING").successful(true));
allow.setHistoricalBalanceLookup(true);
allow.setMempoolCoins(true);
options.setAllow(allow);


Expand Down
33 changes: 20 additions & 13 deletions src/main/java/rosesnow/RoseUtil.java
Expand Up @@ -26,7 +26,10 @@
public class RoseUtil
{

public static Transaction protoToModel( snowblossom.proto.Transaction s_tx, SnowBlossomNode node)
/**
* Node can be null
*/
public static Transaction protoToModel( snowblossom.proto.Transaction s_tx, SnowBlossomNode node, NetworkParams params)
{
Transaction tx = new Transaction();
ChainHash tx_id = new ChainHash(s_tx.getTxHash());
Expand All @@ -47,19 +50,23 @@ public static Transaction protoToModel( snowblossom.proto.Transaction s_tx, Snow
ChainHash src_tx_id = new ChainHash(tx_in.getSrcTxId());
int src_idx = tx_in.getSrcTxOutIdx();

o.setAccount( new AccountIdentifier().address( spec_hash.toAddressString(node.getParams()) ));
o.setAccount( new AccountIdentifier().address( spec_hash.toAddressString(params) ));

snowblossom.proto.Transaction src_tx = node.getDB().getTransactionMap().get(src_tx_id.getBytes());
if (src_tx == null)
{
src_tx = node.getMemPool().getTransaction(src_tx_id);
}
TransactionInner src_tx_inner = TransactionUtil.getInner(src_tx);
long value = tx_in.getValue();

long value = src_tx_inner.getOutputs(src_idx).getValue();
if ((value == 0L) && (node != null))
{
snowblossom.proto.Transaction src_tx = node.getDB().getTransactionMap().get(src_tx_id.getBytes());
if (src_tx == null)
{
src_tx = node.getMemPool().getTransaction(src_tx_id);
}
TransactionInner src_tx_inner = TransactionUtil.getInner(src_tx);

value = src_tx_inner.getOutputs(src_idx).getValue();
}

// Question, should spent amounts be negative? Probably
o.setAmount( getSnowAmount(-value, node.getParams()) );
o.setAmount( getSnowAmount(-value, params) );

o.setCoinChange(
new CoinChange()
Expand All @@ -81,8 +88,8 @@ public static Transaction protoToModel( snowblossom.proto.Transaction s_tx, Snow

long value = tx_out.getValue();
AddressSpecHash spec_hash = new AddressSpecHash( tx_out.getRecipientSpecHash() );
o.setAmount( getSnowAmount(value, node.getParams()) );
o.setAccount( new AccountIdentifier().address( spec_hash.toAddressString(node.getParams()) ));
o.setAmount( getSnowAmount(value, params) );
o.setAccount( new AccountIdentifier().address( spec_hash.toAddressString(params) ));

o.setCoinChange(
new CoinChange()
Expand Down
9 changes: 5 additions & 4 deletions test/integration/ConstructionE2E.java
Expand Up @@ -86,11 +86,12 @@ public ConstructionE2E()
while(true)
{
System.out.println("Waiting for balance on " + gen_addr);
AccountBalanceResponse bal = req("/account/balance",
new AccountBalanceRequest()
AccountCoinsResponse bal = req("/account/coins",
new AccountCoinsRequest()
.accountIdentifier(a_id)
.networkIdentifier(net_id),
AccountBalanceResponse.class);
.networkIdentifier(net_id)
.includeMempool(true),
AccountCoinsResponse.class);

if (bal.getCoins() != null)
{
Expand Down

0 comments on commit d4978db

Please sign in to comment.