Skip to content

Commit

Permalink
rebase | use new struct for passing parameters for new elements
Browse files Browse the repository at this point in the history
  • Loading branch information
rustamlabs authored and janmazak committed Aug 10, 2022
1 parent 0390cde commit 226bb59
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/txHashBuilder.c
Expand Up @@ -309,7 +309,7 @@ void txHashBuilder_addInput(tx_hash_builder_t* builder, const tx_input_t* input)
ASSERT(builder->remainingInputs > 0);
builder->remainingInputs--;

cbor_append_txInput(builder, utxoHashBuffer, utxoHashSize, utxoIndex);
cbor_append_txInput(builder, input->txHashBuffer, utxoHashSize, input->index);
}

static void txHashBuilder_assertCanLeaveInputs(tx_hash_builder_t* builder)
Expand Down Expand Up @@ -1511,7 +1511,7 @@ void txHashBuilder_addCollateral(tx_hash_builder_t* builder, const tx_input_t* c
ASSERT(builder->remainingCollaterals > 0);
builder->remainingCollaterals--;

cbor_append_txInput(builder, utxoHashBuffer, utxoHashSize, utxoIndex);
cbor_append_txInput(builder, collInput->txHashBuffer, utxoHashSize, collInput->index);
}

static void txHashBuilder_assertCanLeaveCollaterals(tx_hash_builder_t* builder)
Expand Down Expand Up @@ -1787,18 +1787,18 @@ void txHashBuilder_enterReferenceInputs(tx_hash_builder_t* builder )
}
void txHashBuilder_addReferenceInput(
tx_hash_builder_t* builder,
const uint8_t* utxoHashBuffer, size_t utxoHashSize,
uint32_t utxoIndex
const tx_input_t* refInput
)
{
_TRACE("state = %d, remainingInputs = %u", builder->state, builder->remainingReferenceInputs);
const size_t utxoHashSize = SIZEOF(refInput->txHashBuffer);

ASSERT(utxoHashSize < BUFFER_SIZE_PARANOIA);
ASSERT(builder->state == TX_HASH_BUILDER_IN_REFERENCE_INPUTS);
ASSERT(builder->remainingReferenceInputs > 0);
builder->remainingReferenceInputs--;

cbor_append_txInput(builder, utxoHashBuffer, utxoHashSize, utxoIndex);
cbor_append_txInput(builder, refInput->txHashBuffer, utxoHashSize, refInput->index);
}


Expand Down
3 changes: 1 addition & 2 deletions src/txHashBuilder.h
Expand Up @@ -319,8 +319,7 @@ void txHashBuilder_addTotalCollateral(tx_hash_builder_t* builder, uint64_t txCol
void txHashBuilder_enterReferenceInputs(tx_hash_builder_t* builder);
void txHashBuilder_addReferenceInput(
tx_hash_builder_t* builder,
const uint8_t* utxoHashBuffer, size_t utxoHashSize,
uint32_t utxoIndex
const tx_input_t* refInput
);
void txHashBuilder_finalize(
tx_hash_builder_t* builder,
Expand Down
16 changes: 9 additions & 7 deletions src/txHashBuilder_test.c
Expand Up @@ -436,7 +436,7 @@ void run_txHashBuilder_test()

txHashBuilder_init(&builder,
ARRAY_LEN(inputs),
(ARRAY_LEN(outputs) + 2) * 2, // +2 for multiasset outputs
(ARRAY_LEN(outputs) + 2) * 2, // +2 for multiasset outputs *2 for new format
true, // ttl
numCertificates, ARRAY_LEN(withdrawals),
true, // metadata
Expand Down Expand Up @@ -504,7 +504,10 @@ void run_txHashBuilder_test()
txHashBuilder_enterCollaterals(&builder);
uint8_t tmp[TX_HASH_LENGTH] = {0};
size_t tmpSize = decode_hex(PTR_PIC(inputs[0].txHashHex), tmp, SIZEOF(tmp));
txHashBuilder_addCollateral(&builder, tmp, tmpSize, inputs[0].index);
tx_input_t input;
memmove(input.txHashBuffer, tmp, tmpSize);
input.index = inputs[0].index;
txHashBuilder_addCollateral(&builder, &input);
}
// ? 14 : required_signers
{
Expand All @@ -524,11 +527,10 @@ void run_txHashBuilder_test()
ITERATE(it, inputs) {
uint8_t tmp[TX_HASH_LENGTH] = {0};
size_t tmpSize = decode_hex(PTR_PIC(it->txHashHex), tmp, SIZEOF(tmp));
txHashBuilder_addReferenceInput(
&builder,
tmp, tmpSize,
it->index
);
tx_input_t input;
memmove(input.txHashBuffer, tmp, tmpSize);
input.index = it->index;
txHashBuilder_addReferenceInput(&builder,&input);
}

uint8_t result[TX_HASH_LENGTH] = {0};
Expand Down

0 comments on commit 226bb59

Please sign in to comment.