根据 https://bitcoinops.org/en/tools/calc-size/
Transaction size = 10.5 + 57.5 * inputsNumber + 43 * outputsNumber
再根据 ordinals 脚本:
fn append_reveal_script_to_builder(&self, mut builder: script::Builder) -> script::Builder {
builder = builder
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(PROTOCOL_ID);
if let Some(content_type) = &self.content_type {
builder = builder
.push_slice(CONTENT_TYPE_TAG)
.push_slice(content_type);
}
if let Some(body) = &self.body {
builder = builder.push_slice(BODY_TAG);
for chunk in body.chunks(520) {
builder = builder.push_slice(chunk);
}
}
builder.push_opcode(opcodes::all::OP_ENDIF)
}
OP_FALSE
OP_IF
OP_PUSH "ord"
OP_PUSH 1
OP_PUSH "text/plain;charset=utf-8"
OP_PUSH 0
OP_PUSH "Hello, world!"
OP_ENDIF
OP_FALSE
: 1OP_IF
: 1OP_PUSH ord
: 1 + 3OP_PUSH 1
: 1 + 1OP_PUSH "image/png"
: 1 + 9OP_PUSH 0
: 2OP_PUSH 图片内容(520字节一个块)
: 3 * (imageSize / 520) + imageSize
OP_ENDIF
: 1
def calcsize(count, contentType, imageSize):
commitTxSize = 10.5 + 57.5 * 1 + 43 * (count + 1)
revealTxSize = 10.5 + 57.5 * 1 + 43 * (count)
ordinalsSize = 1 + 1 + (1+3) + 2 + 1 + len(contentType) + 2 + (3 * (imageSize / 520) + imageSize) + 1
return commitTxSize + revealTxSize + ordinalsSize