-
Notifications
You must be signed in to change notification settings - Fork 19
PR 2 of 3: Add bindings in simplicity-sys crate. #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
apoelstra
merged 3 commits into
BlockstreamResearch:master
from
sanket1729:add_bindings
Dec 17, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #include <stdlib.h> | ||
| #include <stdalign.h> | ||
| #include "simplicity/elements/env.h" | ||
| #include "simplicity/primitive/elements/primitive.h" | ||
|
|
||
| const size_t c_sizeof_rawBuffer = sizeof(rawBuffer); | ||
| const size_t c_sizeof_rawOutput = sizeof(rawOutput); | ||
| const size_t c_sizeof_rawInput = sizeof(rawInput); | ||
| const size_t c_sizeof_rawTransaction = sizeof(rawTransaction); | ||
| const size_t c_sizeof_rawTapEnv = sizeof(rawTapEnv); | ||
| const size_t c_sizeof_txEnv = sizeof(txEnv); | ||
|
|
||
| const size_t c_alignof_rawBuffer = alignof(rawBuffer); | ||
| const size_t c_alignof_rawOutput = alignof(rawOutput); | ||
| const size_t c_alignof_rawInput = alignof(rawInput); | ||
| const size_t c_alignof_rawTransaction = alignof(rawTransaction); | ||
| const size_t c_alignof_rawTapEnv = alignof(rawTapEnv); | ||
| const size_t c_alignof_txEnv = alignof(txEnv); | ||
|
|
||
| void c_set_rawBuffer(rawBuffer *result, const unsigned char *buf, unsigned int len) | ||
| { | ||
| *result = (rawBuffer){.buf = buf, .len = len}; | ||
| } | ||
|
|
||
| void c_set_rawOutput(rawOutput *result, const unsigned char *asset, const unsigned char *value, const unsigned char *nonce, const rawBuffer *scriptPubKey, | ||
| const rawBuffer *surjectionProof, const rawBuffer *rangeProof) | ||
| { | ||
| *result = (rawOutput){.asset = asset, .value = value, .nonce = nonce, .scriptPubKey = *scriptPubKey, .surjectionProof = *surjectionProof, .rangeProof = *rangeProof}; | ||
| } | ||
|
|
||
| void c_set_rawInput(rawInput *result, const rawBuffer *annex, const unsigned char *pegin, const rawBuffer *scriptSig, | ||
| const unsigned char *prevTxid, unsigned int prevIx, | ||
| const unsigned char *asset, const unsigned char *value, const rawBuffer *scriptPubKey, | ||
| unsigned int sequence, | ||
| const unsigned char *blindingNonce, const unsigned char *assetEntropy, const unsigned char *amount, const unsigned char *inflationKeys, | ||
| const rawBuffer *amountRangePrf, const rawBuffer *inflationKeysRangePrf) | ||
| { | ||
| *result = (rawInput){.annex = annex, .scriptSig = *scriptSig, .prevTxid = prevTxid, .pegin = pegin, .issuance = {.blindingNonce = blindingNonce, .assetEntropy = assetEntropy, .amount = amount, .inflationKeys = inflationKeys, .amountRangePrf = *amountRangePrf, .inflationKeysRangePrf = *inflationKeysRangePrf}, .txo = {.asset = asset, .value = value, .scriptPubKey = *scriptPubKey}, .prevIx = prevIx, .sequence = sequence}; | ||
| } | ||
|
|
||
| void c_set_rawTransaction(rawTransaction *result, unsigned int version, | ||
| const rawInput *input, unsigned int numInputs, | ||
| const rawOutput *output, unsigned int numOutputs, | ||
| unsigned int lockTime) | ||
| { | ||
| *result = (rawTransaction){ | ||
| .version = version, | ||
| .input = input, | ||
| .numInputs = numInputs, | ||
| .output = output, | ||
| .numOutputs = numOutputs, | ||
| .lockTime = lockTime, | ||
| }; | ||
| } | ||
|
|
||
| void c_set_rawTapEnv(rawTapEnv *result, const unsigned char *controlBlock, unsigned char branchLen, const unsigned char *scriptCMR) | ||
| { | ||
| *result = (rawTapEnv){.controlBlock = controlBlock, .branchLen = branchLen, .scriptCMR = scriptCMR}; | ||
| } | ||
|
|
||
| void c_set_txEnv(txEnv *result, const transaction *tx, const tapEnv *taproot, const unsigned char *genesisHash, unsigned int ix) | ||
| { | ||
| sha256_midstate genesis; | ||
| sha256_toMidstate(genesis.s, genesisHash); | ||
| *result = build_txEnv(tx, taproot, &genesis, ix); | ||
| } | ||
|
|
||
| void c_free_tapEnv(tapEnv *env) | ||
| { | ||
| free(env); | ||
| } | ||
|
|
||
| void c_free_transaction(transaction *tx) | ||
| { | ||
| free(tx); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #ifndef WRAPPERS_H | ||
| #define WRAPPERS_H | ||
| #include "simplicity/frame.h" | ||
|
|
||
| #include <stdalign.h> | ||
|
|
||
| const size_t c_sizeof_UWORD = sizeof(UWORD); | ||
| const size_t c_sizeof_frameItem = sizeof(frameItem); | ||
|
|
||
| const size_t c_alignof_UWORD = alignof(UWORD); | ||
| const size_t c_alignof_frameItem = alignof(frameItem); | ||
|
|
||
| void c_initReadFrame(frameItem *frame, size_t n, UWORD *from) | ||
| { | ||
| *frame = initReadFrame(n, from); | ||
| } | ||
|
|
||
| void c_initWriteFrame(frameItem *frame, size_t n, UWORD *from) | ||
| { | ||
| *frame = initWriteFrame(n, from); | ||
| } | ||
|
|
||
| /* Expose readBit. Internal readBit is static inline. */ | ||
| bool c_readBit(frameItem *frame) | ||
| { | ||
| return readBit(frame); | ||
| } | ||
|
|
||
| /* Expose writeBit. Internal writeBit is static inline. */ | ||
| void c_writeBit(frameItem *frame, bool bit) | ||
apoelstra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| writeBit(frame, bit); | ||
| } | ||
|
|
||
| void c_forwardBits(frameItem *frame, size_t n) | ||
| { | ||
| forwardBits(frame, n); | ||
| } | ||
|
|
||
| void c_skipBits(frameItem *frame, size_t n) | ||
| { | ||
| skipBits(frame, n); | ||
| } | ||
|
|
||
| #endif | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.