Skip to content

Commit

Permalink
Merge pull request #1362 from ergoplatform/v4.0.12
Browse files Browse the repository at this point in the history
Candidate for 4.0.12
  • Loading branch information
kushti authored Jun 3, 2021
2 parents b0a0b6a + 897f463 commit 04c1424
Show file tree
Hide file tree
Showing 45 changed files with 1,766 additions and 305 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ To run specific Ergo version `<VERSION>` as a service with custom config `/path/
-e MAX_HEAP=3G \
ergoplatform/ergo:<VERSION> --<networkId> -c /etc/myergo.conf

Available versions can be found on [Ergo Docker image page](https://hub.docker.com/r/ergoplatform/ergo/tags), for example, `v4.0.11`.
Available versions can be found on [Ergo Docker image page](https://hub.docker.com/r/ergoplatform/ergo/tags), for example, `v4.0.12`.

This will connect to the Ergo mainnet or testnet following your configuration passed in `myergo.conf` and network flag `--<networkId>`. Every default config value would be overwritten with corresponding value in `myergo.conf`. `MAX_HEAP` variable can be used to control how much memory can the node consume.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.ergoplatform.ErgoLikeTransaction;
import org.ergoplatform.UnsignedErgoLikeTransaction;
import scala.collection.JavaConversions;
import sigmastate.basics.DLogProtocol;
import java.util.Map;

/**
* A wrapper over naive Ergo prover implementation.
Expand All @@ -18,4 +20,14 @@ public ErgoLikeTransaction prove(UnsignedErgoLikeTransaction unsignedTx, DLogPro
return org.ergoplatform.wallet.interpreter.ErgoUnsafeProver.prove(unsignedTx, sk);
}

/**
* Signs all inputs of a given `unsignedTx`.
*
* @return signed transaction
*/
public ErgoLikeTransaction prove(UnsignedErgoLikeTransaction unsignedTx, Map<String, DLogProtocol.DLogProverInput> sks) {
// JavaConversions used to support Scala 2.11
return org.ergoplatform.wallet.interpreter.ErgoUnsafeProver.prove(unsignedTx, JavaConversions.mapAsScalaMap(sks));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.ergoplatform.wallet.interpreter

import org.ergoplatform.{ErgoLikeTransaction, Input, UnsignedErgoLikeTransaction}
import scorex.util.encode.Base16
import sigmastate.basics.DLogProtocol.DLogProverInput
import sigmastate.interpreter.{ContextExtension, ProverResult}

Expand All @@ -15,7 +16,7 @@ object ErgoUnsafeProver {
import org.ergoplatform.wallet.crypto.ErgoSignature._

/**
* Signs all inputs of a given `unsignedTx`.
* Signs all inputs of a given `unsignedTx`, if all the inputs are associated with the same keypair.
*
* @note this method does not validate the cost of the given transaction
* @return signed transaction
Expand All @@ -29,4 +30,24 @@ object ErgoUnsafeProver {
new ErgoLikeTransaction(inputs, unsignedTx.dataInputs, unsignedTx.outputCandidates)
}

/**
* Signs all inputs of a given `unsignedTx`.
*
* @note this method does not validate the cost of the given transaction
* @return signed transaction
*/
def prove(unsignedTx: UnsignedErgoLikeTransaction,
sks: scala.collection.Map[String, DLogProverInput]): ErgoLikeTransaction = {

val inputs = unsignedTx.inputs.map { unsignedInput =>
val inputId = Base16.encode(unsignedInput.boxId)

val sk = sks(inputId)

val sig = ProverResult(sign(unsignedTx.messageToSign, sk.w), ContextExtension.empty)
Input(unsignedInput.boxId, sig)
}
new ErgoLikeTransaction(inputs, unsignedTx.dataInputs, unsignedTx.outputCandidates)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import org.ergoplatform.wallet.secrets.ExtendedSecretKey;
import org.ergoplatform.wallet.serialization.JsonCodecsWrapper;
import scorex.util.Random;
import sigmastate.basics.DLogProtocol;

import java.util.HashMap;
import java.util.Map;

public class CreateTransactionDemo {

/**
* A demo describing the process of creating simple payment transaction.
* A demo describing the process of creating simple payment transaction with one key.
* Note, more complex transaction would require more steps which are not described in this demo.
*/
public void createTransaction() throws Exception {
Expand Down Expand Up @@ -54,4 +58,52 @@ public void createTransaction() throws Exception {
System.out.println(json.toString());
}

/**
* A demo describing the process of creating simple payment transaction with multiple keys.
* Note, more complex transaction would require more steps which are not described in this demo.
*/
public static void createTransactionMultipleKeys() throws Exception {
ErgoAddressEncoder encoder = new ErgoAddressEncoder((byte) 0x00);

String receiverAddressStr = "9fKYyGuV3wMYFYzWBR1FDgc61CFV2hbGLrY6S3wgH1r4xJcwLnq";
ErgoAddress receiverAddress = encoder.fromString(receiverAddressStr).get();

// Create second address
byte[] entropy1 = Random.randomBytes(32);
ExtendedSecretKey extendedSecretKey1 = ExtendedSecretKey.deriveMasterKey(entropy1);
ErgoAddress changeAddress = P2PKAddress.apply(extendedSecretKey1.privateInput().publicImage(), encoder);

byte[] entropy2 = Random.randomBytes(32);
ExtendedSecretKey extendedSecretKey2 = ExtendedSecretKey.deriveMasterKey(entropy2);


int transferAmt = 25000000; // amount to transfer
int feeAmt = 1000000; // minimal fee amount
int changeAmt = 20000; // amount to return back

int currentNetworkHeight = 32987; // from explorer `https://api.ergoplatform.com/blocks`

// from explorer `https://api.ergoplatform.com/transactions/boxes/byAddress/unspent/{myAddress}`
Map<String, DLogProtocol.DLogProverInput> myInputs = new HashMap<String, DLogProtocol.DLogProverInput>();
myInputs.put("430e80ca31a25400e77dac0ad14c1cd39cb09dc3f7c1c384dce9aef19b604e27", extendedSecretKey1.privateInput());
myInputs.put("d9ba3ed2f55bc61ec90b7ee3949362a9a20fbf8514d2306eb97f14e07d234797", extendedSecretKey2.privateInput());

UnsignedErgoLikeTransaction unsignedTx = Utils.paymentTransaction(
receiverAddress,
changeAddress,
transferAmt,
feeAmt,
changeAmt,
myInputs.keySet().toArray(new String[0]),
currentNetworkHeight
);

ErgoLikeTransaction tx = new ErgoUnsafeProver().prove(unsignedTx, myInputs);

// print transaction JSON
// then the transaction can be broadcasted by sending the json to
// https://api.ergoplatform.com/api/v0/transactions/send (POST request)
Json json = JsonCodecsWrapper.ergoLikeTransactionEncoder().apply(tx);
System.out.println(json.toString());
}
}
184 changes: 182 additions & 2 deletions src/main/resources/api/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: "3.0.2"

info:
version: "4.0.11"
version: "4.0.12"
title: Ergo Node API
description: API docs for Ergo Node. Models are shared between all Ergo products
contact:
Expand Down Expand Up @@ -1243,6 +1243,48 @@ components:
adProofsId:
$ref: '#/components/schemas/ModifierId'

PopowHeader:
type: object
required:
- header
- interlinks
properties:
header:
$ref: '#/components/schemas/BlockHeader'
interlinks:
description: Array of header interlinks
type: array
items:
$ref: '#/components/schemas/ModifierId'

NipopowProof:
type: object
required:
- m
- k
- prefix
- suffixHead
- suffixTail
properties:
m:
description: security parameter (min μ-level superchain length)
type: number
k:
description: security parameter (min suffix length, >= 1)
type: number
prefix:
description: proof prefix headers
type: array
items:
$ref: '#/components/schemas/PopowHeader'
suffixHead:
$ref: '#/components/schemas/PopowHeader'
suffixTail:
description: tail of the proof suffix headers
type: array
items:
$ref: '#/components/schemas/BlockHeader'

BlockHeader:
type: object
required:
Expand Down Expand Up @@ -1878,7 +1920,6 @@ components:
error:
type: string


ApiError:
type: object
required:
Expand Down Expand Up @@ -2238,6 +2279,145 @@ paths:
schema:
$ref: '#/components/schemas/ApiError'

/nipopow/popowHeaderById/{headerId}:
get:
summary: Construct PoPow header according to given header id
operationId: getPopowHeaderById
tags:
- nipopow
parameters:
- in: path
name: headerId
required: true
description: ID of wanted header
schema:
type: string
responses:
'200':
description: PoPow header object
content:
application/json:
schema:
$ref: '#/components/schemas/PopowHeader'
'404':
description: Header of extension of a corresponding block are not available
content:
application/json:
schema:
$ref: '#/components/schemas/ApiError'
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ApiError'

/nipopow/popowHeaderByHeight/{height}:
get:
summary: Construct PoPow header for best header at given height
operationId: getPopowHeaderByHeight
tags:
- nipopow
parameters:
- in: path
name: height
required: true
description: Height of a wanted header
schema:
type: integer
format: int32
responses:
'200':
description: PoPow header object
content:
application/json:
schema:
$ref: '#/components/schemas/PopowHeader'
'404':
description: Header of extension of a corresponding block are not available
content:
application/json:
schema:
$ref: '#/components/schemas/ApiError'
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ApiError'

/nipopow/proof/{minChainLength}/{suffixLength}:
get:
summary: Construct PoPoW proof for given min superchain length and suffix length
operationId: getPopowProof
tags:
- nipopow
parameters:
- in: path
name: minChainLength
required: true
description: Minimal superchain length
schema:
type: number
- in: path
name: suffixLength
required: true
description: Suffix length
schema:
type: number
responses:
'200':
description: Nipopow proof object
content:
application/json:
schema:
$ref: '#/components/schemas/NipopowProof'
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ApiError'

/nipopow/proof/{minChainLength}/{suffixLength}/{headerId}:
get:
summary: Construct PoPoW proof for given min superchain length, suffix length and header ID
operationId: getPopowProofByHeaderId
tags:
- nipopow
parameters:
- in: path
name: minChainLength
required: true
description: Minimal superchain length
schema:
type: number
- in: path
name: suffixLength
required: true
description: Suffix length
schema:
type: number
- in: path
name: headerId
required: true
description: ID of wanted header
schema:
type: string
responses:
'200':
description: Nipopow proof object
content:
application/json:
schema:
$ref: '#/components/schemas/NipopowProof'
default:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/ApiError'

/info:
get:
summary: Get the information about the Node
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/mainnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ scorex {
network {
magicBytes = [1, 0, 2, 4]
bindAddress = "0.0.0.0:9030"
nodeName = "ergo-mainnet-4.0.11"
nodeName = "ergo-mainnet-4.0.12"
nodeName = ${?NODENAME}
knownPeers = [
"46.4.112.10:9030",
"213.239.193.208:9030",
"51.75.52.63:9030",
"159.65.11.55:9030",
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/testnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ scorex {
network {
magicBytes = [2, 0, 0, 2]
bindAddress = "0.0.0.0:9020"
nodeName = "ergo-testnet-4.0.11"
nodeName = "ergo-testnet-4.0.12"
nodeName = ${?NODENAME}
knownPeers = [
"213.239.193.208:9020",
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/org/ergoplatform/ErgoApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class ErgoApp(args: Args) extends ScorexLogging {
PeersApiRoute(peerManagerRef, networkControllerRef, timeProvider, settings.restApi),
InfoApiRoute(statsCollectorRef, settings.restApi, timeProvider),
BlocksApiRoute(nodeViewHolderRef, readersHolderRef, ergoSettings),
NipopowApiRoute(nodeViewHolderRef, readersHolderRef, ergoSettings),
TransactionsApiRoute(readersHolderRef, nodeViewHolderRef, settings.restApi),
WalletApiRoute(readersHolderRef, nodeViewHolderRef, ergoSettings),
UtxoApiRoute(readersHolderRef, settings.restApi),
Expand Down
Loading

0 comments on commit 04c1424

Please sign in to comment.