您正在查看: Surou 发布的文章

获取用户真正转发了某个twitter

import tweepy

# 你的Twitter API Key
consumer_key = 'your_consumer_key'
consumer_secret = 'your_consumer_secret'
access_token = 'your_access_token'
access_token_secret = 'your_access_token_secret'

# 设置API访问
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

# 检查用户是否转发了推文
def check_retweet(username, tweet_id):
    try:
        # 获取用户的转发列表
        retweets = api.retweets(tweet_id)
        for retweet in retweets:
            if retweet.user.screen_name == username:
                return True
        return False
    except tweepy.TweepError as e:
        print(f"Error: {e}")
        return False

# 使用示例
username = 'example_user'
tweet_id = '1234567890123456789'  # 你的推文ID
is_retweeted = check_retweet(username, tweet_id)
print(f"{username} has {'retweeted' if is_retweeted else 'not retweeted'} the tweet.")

https://developer.x.com/en/docs/twitter-api/tweets/retweets/introduction
https://developer.twitter.com/apitools/api?endpoint=%2F2%2Fusers%2F%7Bid%7D%2Fretweets&method=post

检查签名对于给定的签名者和数据哈希是否有效

github: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/659f3063f82422cef820de746444e6f6cba6ca7c/contracts/utils/cryptography/SignatureChecker.sol

/**
     * @dev Checks if a signature is valid for a given signer and data hash. If the signer is a smart contract, the
     * signature is validated against that smart contract using ERC-1271, otherwise it's validated using `ECDSA.recover`.
     *
     * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
     * change through time. It could return true at block N and false at block N+1 (or the opposite).
     */
    function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) {
        if (signer.code.length == 0) {
            (address recovered, ECDSA.RecoverError err, ) = ECDSA.tryRecover(hash, signature);
            return err == ECDSA.RecoverError.NoError && recovered == signer;
        } else {
            return isValidERC1271SignatureNow(signer, hash, signature);
        }
    }

测试例子

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.19;

import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";

contract TestSignatureChecker {
    function verify(address _signer, bytes32 messageHash,  bytes memory _signature) external view returns(bool) {
        return SignatureChecker.isValidSignatureNow(_signer, messageHash, _signature);
    }
}

用于以太坊 RLP 解码的 Solidity 库

安装

  1. npm install solidity-rlp在项目目录中。请确保通过 npm 安装以便及时更新!
  2. import "solidity-rlp/contracts/RLPReader.sol"在所需的智能合约中。

github: https://github.com/hamdiallam/Solidity-RLP.git

测试例子

import "solidity-rlp/contracts/RLPReader.sol"

contract SomeContract {

    // optional way to attach library functions to these data types.
    using RLPReader for RLPReader.RLPItem;
    using RLPReader for RLPReader.Iterator;
    using RLPReader for bytes;

    // lets assume that rlpBytes is an encoding of [[1, "nested"], 2, 0x<Address>]
    function someFunctionThatTakesAnEncodedItem(bytes memory rlpBytes) public {
        RLPReader.RLPItem[] memory ls = rlpBytes.toRlpItem().toList(); // must convert to an rlpItem first!

        RLPReader.RLPItem memory item = ls[0]; // the encoding of [1, "nested"].
        item.toList()[0].toUint(); // 1
        string(item.toList()[1].toBytes()); // "nested"

        ls[1].toUint(); // 2
        ls[2].toAddress(); // 0x<Address>
    }

    // lets assume rlpBytes is an encoding of [["sublist"]]
    function someFunctionThatDemonstratesIterators(bytes memory rlpBytes) public {
        RLPReader.Iterator memory iter = rlpBytes.toRlpItem().iterator();
        RLPReader.Iterator memory subIter = iter.next().iterator();

        // iter.hasNext() == false
        // string(subIter.next().toBytes()) == "sublist"
        // subIter.hasNext() == false
    }
}

参考

https://ethereum.stackexchange.com/questions/42732/how-to-rlp-encode-messages-in-solidity

Opentonapi 是TonAPI的开源版本,与其 100% 兼容

Opentonapi 简化了基于 TON 的应用程序的开发,并提供了以 Jettons、NFT 等高级概念为中心的 API,以保留访问低级细节的方式。

Opentonapi 是TonAPI的开源版本,与其 100% 兼容。

主要区别在于,TonAPI 维护整个 TON 区块链的内部索引,并提供有关区块链中任何实体的信息,包括 Jettons、NFT、账户、交易、痕迹等。

https://github.com/tonkeeper/opentonapi

Go primitives to work with TON

Go implementation of libraries for TON blockchain.

github: https://github.com/tonkeeper/tongo.git