MCPcopy Create free account
hub / github.com/ElementsProject/elements / lookup_fee

Function lookup_fee

src/simplicity/elements/elementsJets.c:176–189  ·  view source on GitHub ↗

Lookup the assetFee from a sorted array of feeOutputs by the given assetid, returning 0 if no entry is found. * * Precondition: NULL != assetid; * feeOutputs is uniquely sorted by it asset.data.s field, which is to say * for all 0 <= i < j < len, * 0 < memcmp(feeOutputs[j]->asset.data.s, feeOutputs[i]->asset.data.s, sizeof(feeOutputs[i]->asset.data.

Source from the content-addressed store, hash-verified

174 * 0 < memcmp(feeOutputs[j]->asset.data.s, feeOutputs[i]->asset.data.s, sizeof(feeOutputs[i]->asset.data.s));
175 */
176static uint_fast64_t lookup_fee(const sha256_midstate* assetid, const sigOutput* const * feeOutputs, uint_fast32_t len) {
177 /* This loop runs in O(log(len)) time. */
178 while(len) {
179 int cmp = memcmp(assetid->s, feeOutputs[len/2]->asset.data.s, sizeof(assetid->s));
180 if (0 == cmp) return feeOutputs[len/2]->assetFee;
181 if (0 < cmp) {
182 feeOutputs += len/2 + 1;
183 len -= len/2 + 1;
184 } else {
185 len /= 2;
186 }
187 }
188 return 0;
189}
190
191/* version : ONE |- TWO^32 */
192bool simplicity_version(frameItem* dst, frameItem src, const txEnv* env) {

Callers 1

simplicity_total_feeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected