Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chain-libs
Submodule chain-libs updated 77 files
+158 −7 cardano-legacy-address/src/address.rs
+1 −1 cardano-legacy-address/src/lib.rs
+17 −0 chain-core/src/mempack.rs
+1 −1 chain-crypto/src/sign.rs
+2 −4 chain-crypto/src/testing.rs
+185 −0 chain-impl-mockchain/doc/format.abnf
+47 −2 chain-impl-mockchain/doc/format.md
+73 −0 chain-impl-mockchain/doc/overview.md
+1 −1 chain-impl-mockchain/src/account.rs
+48 −4 chain-impl-mockchain/src/accounting/account/account_state.rs
+19 −13 chain-impl-mockchain/src/accounting/account/mod.rs
+118 −20 chain-impl-mockchain/src/certificate/delegation.rs
+155 −3 chain-impl-mockchain/src/certificate/mod.rs
+138 −63 chain-impl-mockchain/src/certificate/pool.rs
+17 −12 chain-impl-mockchain/src/certificate/test.rs
+25 −86 chain-impl-mockchain/src/fee.rs
+38 −26 chain-impl-mockchain/src/fragment/mod.rs
+7 −0 chain-impl-mockchain/src/key.rs
+53 −59 chain-impl-mockchain/src/leadership/genesis/mod.rs
+55 −99 chain-impl-mockchain/src/ledger/check.rs
+91 −0 chain-impl-mockchain/src/ledger/info.rs
+17 −22 chain-impl-mockchain/src/ledger/iter.rs
+192 −154 chain-impl-mockchain/src/ledger/ledger.rs
+1 −0 chain-impl-mockchain/src/ledger/mod.rs
+2 −4 chain-impl-mockchain/src/ledger/tests/discrimination_tests.rs
+1 −2 chain-impl-mockchain/src/ledger/tests/initial_funds_tests.rs
+7 −192 chain-impl-mockchain/src/ledger/tests/ledger_tests.rs
+45 −0 chain-impl-mockchain/src/ledger/tests/macros.rs
+6 −4 chain-impl-mockchain/src/ledger/tests/mod.rs
+50 −385 chain-impl-mockchain/src/ledger/tests/transaction_tests.rs
+5 −6 chain-impl-mockchain/src/ledger/tests/update_tests.rs
+5 −1 chain-impl-mockchain/src/legacy.rs
+0 −1 chain-impl-mockchain/src/lib.rs
+1 −1 chain-impl-mockchain/src/multisig/ledger.rs
+28 −59 chain-impl-mockchain/src/stake/delegation.rs
+10 −11 chain-impl-mockchain/src/stake/distribution.rs
+5 −18 chain-impl-mockchain/src/testing/builders/cert_builder.rs
+3 −4 chain-impl-mockchain/src/testing/builders/mod.rs
+0 −1 chain-impl-mockchain/src/testing/builders/proposal_builder.rs
+121 −109 chain-impl-mockchain/src/testing/builders/tx_builder.rs
+0 −113 chain-impl-mockchain/src/testing/builders/tx_cert_builder.rs
+1 −8 chain-impl-mockchain/src/testing/data/address.rs
+56 −0 chain-impl-mockchain/src/testing/data/keys.rs
+2 −0 chain-impl-mockchain/src/testing/data/mod.rs
+229 −44 chain-impl-mockchain/src/testing/ledger.rs
+4 −1 chain-impl-mockchain/src/testing/mod.rs
+0 −15 chain-impl-mockchain/src/testing/requests.rs
+181 −0 chain-impl-mockchain/src/transaction/builder.rs
+77 −0 chain-impl-mockchain/src/transaction/element.rs
+252 −0 chain-impl-mockchain/src/transaction/input.rs
+266 −0 chain-impl-mockchain/src/transaction/io.rs
+137 −55 chain-impl-mockchain/src/transaction/mod.rs
+160 −0 chain-impl-mockchain/src/transaction/payload.rs
+393 −156 chain-impl-mockchain/src/transaction/transaction.rs
+0 −217 chain-impl-mockchain/src/transaction/transfer.rs
+16 −30 chain-impl-mockchain/src/transaction/witness.rs
+29 −63 chain-impl-mockchain/src/txbuilder.rs
+33 −35 chain-impl-mockchain/src/utxo.rs
+29 −0 chain-impl-mockchain/src/value.rs
+0 −1 chain-time/src/era.rs
+8 −1 imhamt/src/bitmap.rs
+12 −2 imhamt/src/hamt.rs
+8 −0 imhamt/src/node/reference.rs
+1 −0 network-core/Cargo.toml
+2 −0 network-core/src/server.rs
+38 −46 network-core/src/server/block.rs
+21 −16 network-core/src/server/fragment.rs
+16 −15 network-core/src/server/gossip.rs
+48 −0 network-core/src/server/request_stream.rs
+2 −0 network-grpc/src/server.rs
+55 −342 network-grpc/src/service.rs
+197 −0 network-grpc/src/service/request_stream.rs
+73 −0 network-grpc/src/service/response_future.rs
+62 −0 network-grpc/src/service/response_stream.rs
+229 −0 network-grpc/src/service/subscription.rs
+8 −14 typed-bytes/src/builder.rs
+3 −3 typed-bytes/src/lib.rs
38 changes: 26 additions & 12 deletions examples/faucet/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ fastify.post('/send-money/:destinationAddress', async (request, reply) => {
Input,
Value,
Fee,
TransactionFinalizer,
Fragment,
PrivateKey,
Witness,
SpendingCounter,
Hash,
Account,
InputOutputBuilder,
PayloadAuthData,
Payload,
Witnesses,
// eslint-disable-next-line camelcase
uint8array_to_hex
} = await chainLibs;
Expand All @@ -63,7 +66,7 @@ fastify.post('/send-money/:destinationAddress', async (request, reply) => {
fastify.config.JORMUNGANDR_API
);

const txbuilder = TransactionBuilder.new_no_payload();
const iobuilder = InputOutputBuilder.empty();

const secretKey = PrivateKey.from_bech32(fastify.config.SECRET_KEY);
const faucetAccount = Account.from_public_key(secretKey.to_public());
Expand All @@ -79,9 +82,9 @@ fastify.post('/send-money/:destinationAddress', async (request, reply) => {
Value.from_str(inputAmount.toString())
);

txbuilder.add_input(input);
iobuilder.add_input(input);

txbuilder.add_output(
iobuilder.add_output(
Address.from_string(request.params.destinationAddress),
Value.from_str(fastify.config.LOVELACES_TO_GIVE.toString())
);
Expand All @@ -93,36 +96,47 @@ fastify.post('/send-money/:destinationAddress', async (request, reply) => {
);

// The amount is exact, that's why we use `forget()`
const finalizedTx = txbuilder.seal_with_output_policy(feeAlgorithm, OutputPolicy.forget());

const finalizer = new TransactionFinalizer(finalizedTx);
const IOs = iobuilder.seal_with_output_policy(
Payload.no_payload(),
feeAlgorithm,
OutputPolicy.forget()
);

// To get the account counter used for signing
const accountStatus = await jormungandrApi.getAccountStatus(
fastify.config.JORMUNGANDR_API,
uint8array_to_hex(secretKey.to_public().as_bytes())
);

const builderSetWitness = new TransactionBuilder()
.no_payload()
.set_ios(IOs.inputs(), IOs.outputs());

const witness = Witness.for_account(
Hash.from_hex(nodeSettings.block0Hash),
finalizer.get_tx_sign_data_hash(),
builderSetWitness.get_auth_data_for_witness(),
secretKey,
SpendingCounter.from_u32(accountStatus.counter)
);

finalizer.set_witness(0, witness);
const witnesses = Witnesses.new();
witnesses.add(witness);

const signedTx = finalizer.finalize();
const signedTx = builderSetWitness
.set_witnesses(witnesses)
.set_payload_auth(PayloadAuthData.for_no_payload());

const message = Fragment.from_authenticated_transaction(signedTx);
const message = Fragment.from_transaction(signedTx);

// Send the transaction
await jormungandrApi.postMsg(
fastify.config.JORMUNGANDR_API,
message.as_bytes()
);

reply.code(200).send(`transaction id: ${uint8array_to_hex(message.id().as_bytes())}`);
reply
.code(200)
.send(`transaction id: ${uint8array_to_hex(message.id().as_bytes())}`);
} catch (err) {
fastify.log.error(err);
}
Expand Down
Loading