当前位置: 首页>>代码示例>>Java>>正文


Java Transaction.SIGHASH_ANYONECANPAY_VALUE属性代码示例

本文整理汇总了Java中com.google.bitcoin.core.Transaction.SIGHASH_ANYONECANPAY_VALUE属性的典型用法代码示例。如果您正苦于以下问题:Java Transaction.SIGHASH_ANYONECANPAY_VALUE属性的具体用法?Java Transaction.SIGHASH_ANYONECANPAY_VALUE怎么用?Java Transaction.SIGHASH_ANYONECANPAY_VALUE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.google.bitcoin.core.Transaction的用法示例。


在下文中一共展示了Transaction.SIGHASH_ANYONECANPAY_VALUE属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: calcSigHashValue

/** Calculates the byte used in the protocol to represent the combination of mode and anyoneCanPay. */
public static int calcSigHashValue(Transaction.SigHash mode, boolean anyoneCanPay) {
    int sighashFlags = mode.ordinal() + 1;
    if (anyoneCanPay)
        sighashFlags |= Transaction.SIGHASH_ANYONECANPAY_VALUE;
    return sighashFlags;
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:7,代码来源:TransactionSignature.java

示例2: isEncodingCanonical

/**
 * Returns true if the given signature is has canonical encoding, and will thus be accepted as standard by
 * the reference client. DER and the SIGHASH encoding allow for quite some flexibility in how the same structures
 * are encoded, and this can open up novel attacks in which a man in the middle takes a transaction and then
 * changes its signature such that the transaction hash is different but it's still valid. This can confuse wallets
 * and generally violates people's mental model of how Bitcoin should work, thus, non-canonical signatures are now
 * not relayed by default.
 */
public static boolean isEncodingCanonical(byte[] signature) {
    // See reference client's IsCanonicalSignature, https://bitcointalk.org/index.php?topic=8392.msg127623#msg127623
    // A canonical signature exists of: <30> <total len> <02> <len R> <R> <02> <len S> <S> <hashtype>
    // Where R and S are not negative (their first byte has its highest bit not set), and not
    // excessively padded (do not start with a 0 byte, unless an otherwise negative number follows,
    // in which case a single 0 byte is necessary and even required).
    if (signature.length < 9 || signature.length > 73)
        return false;

    int hashType = signature[signature.length-1] & ((int)(~Transaction.SIGHASH_ANYONECANPAY_VALUE));
    if (hashType < (Transaction.SigHash.ALL.ordinal() + 1) || hashType > (Transaction.SigHash.SINGLE.ordinal() + 1))
        return false;

    //                   "wrong type"                  "wrong length marker"
    if ((signature[0] & 0xff) != 0x30 || (signature[1] & 0xff) != signature.length-3)
        return false;

    int lenR = signature[3] & 0xff;
    if (5 + lenR >= signature.length || lenR == 0)
        return false;
    int lenS = signature[5+lenR] & 0xff;
    if (lenR + lenS + 7 != signature.length || lenS == 0)
        return false;

    //    R value type mismatch          R value negative
    if (signature[4-2] != 0x02 || (signature[4] & 0x80) == 0x80)
        return false;
    if (lenR > 1 && signature[4] == 0x00 && (signature[4+1] & 0x80) != 0x80)
        return false; // R value excessively padded

    //       S value type mismatch                    S value negative
    if (signature[6 + lenR - 2] != 0x02 || (signature[6 + lenR] & 0x80) == 0x80)
        return false;
    if (lenS > 1 && signature[6 + lenR] == 0x00 && (signature[6 + lenR + 1] & 0x80) != 0x80)
        return false; // S value excessively padded

    return true;
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:46,代码来源:TransactionSignature.java

示例3: anyoneCanPay

public boolean anyoneCanPay() {
    return (sighashFlags & Transaction.SIGHASH_ANYONECANPAY_VALUE) != 0;
}
 
开发者ID:testzcrypto,项目名称:animecoinj,代码行数:3,代码来源:TransactionSignature.java


注:本文中的com.google.bitcoin.core.Transaction.SIGHASH_ANYONECANPAY_VALUE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。