Bitcoin Forum
October 20, 2018, 02:18:57 PM *
News: Make sure you are not using versions of Bitcoin Core other than 0.17.0 [Torrent], 0.16.3, 0.15.2, or 0.14.3. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Pushing data to CScript  (Read 218 times)
myquidproquo
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
September 02, 2017, 08:54:54 PM
 #1

Hi!

Just started learning Bitcoin Core code to better understand Bitcoin.
My C is a little bit rusty and I know just a little bit of C++ but I think I will pick it up fast as I progress.

I was thinking that the Bitcoin Script was a good place to start.
This is really basic so I hope I don't offend anyone.

What's the easiest way to push data (other than OP_CODES) to the CScript stack?

Code:
    CScript *cScript;
    opcodetype test;

    cScript = new CScript();
    *cScript << opcodetype::OP_HASH160;
   
    //Pushing 20 bytes
    *cScript << opcodetype::0x14
   
    //Need to push some address here but this is not the right way to do it...
    *cScript << "71ed53322d470bb96657deb786b94f97dd46fb15";
   
    *cScript << opcodetype::OP_EQUAL;


Thank you.
"Apparently, so I am told, there exist "people" who prefer to wipe sitting down. From the front. Initial research indicates it could be up to half the population." -- benjamindees
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1540045137
Hero Member
*
Offline Offline

Posts: 1540045137

View Profile Personal Message (Offline)

Ignore
1540045137
Reply with quote  #2

1540045137
Report to moderator
1540045137
Hero Member
*
Offline Offline

Posts: 1540045137

View Profile Personal Message (Offline)

Ignore
1540045137
Reply with quote  #2

1540045137
Report to moderator
myquidproquo
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
September 02, 2017, 10:15:37 PM
 #2

I managed to do it. Found out about "utilsrencodings".

Code:
    CScript *cScript;
    opcodetype test;
    vector<unsigned char> addr = ParseHex("71ed53322d470bb96657deb786b94f97dd46fb15");

    cScript = new CScript();
    *cScript << opcodetype::OP_HASH160;
    *cScript << addr;
    *cScript << opcodetype::OP_EQUAL;
    printf("%d\n",cScript->IsPayToScriptHash());



Thanks.
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!