Git Product home page Git Product logo

Comments (17)

ader1990 avatar ader1990 commented on August 16, 2024 1

I found the issue I had in my code:
I should have written:

buffer=Buffer.from(atob(Buffer.from(data, 'base64')), "hex")

instead of:

buffer=Buffer(atob(Buffer.from(data, 'base64')), "hex")

from node-webdollar.

ibudisteanu avatar ibudisteanu commented on August 16, 2024

Try to extract the first data from the Block raw bytes, then proceed to extract the 2nd data, and 3rd and so on. In case you can't extract the first data, then probably you don't have the block raw bytes or in the correct format.

from node-webdollar.

ader1990 avatar ader1990 commented on August 16, 2024

substr(buffer, 0, 32).toString("hex")
'3030303037653330313337313162633132366138373038613332343437326664'

The problem is that I cannot check if this is okay or not unless I ask someone who can actually confirm it.

from node-webdollar.

ibudisteanu avatar ibudisteanu commented on August 16, 2024

This is what I got from interrogating the this.blocks[0].serializeBlock().toString("hex")

00007e3013711bc126a8708a324472fdfcf6855cef1f979b0df43475c9568e330000e7240001731d46c131eb6dd4667a96bdc27baf9223bec72c3468dfb6ba52c460e76423a4000004476c1d355b03205412204804e427f9a56de15f10f0c80fc530fecde9a48ae6aede861e9903e5422f7c111358032dfe6ca37aad8bdd5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456000000000a1cfceb215aeac46c0b7eea0d5da9defd927e24504b757e6c3d3702853c9c9901000001731d46c131eb6dd4667a96bdc27baf9223bec72c3468dfb6ba52c460e76423a4

image

from node-webdollar.

ibudisteanu avatar ibudisteanu commented on August 16, 2024

block[1] `

000125988a04e701c324eaa43798751e24422a8c65a3fc2fa78d5dd8d81d6cb600003c26000100007e3013711bc126a8708a324472fdfcf6855cef1f979b0df43475c9568e3300000472920ffd31f9752f90a0bd4c9fba25790b5340d7900b0438273a76b834b9f17856bd87b88551446a84650bdb7525ec27326e55ffd85df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c945600000000229cba7cd7926a980ddae11625db7a7a5e0f5a86267d44ab1689f140cd7a4b7303000001731d46c131eb6dd4667a96bdc27baf9223bec72c3468dfb6ba52c460e76423a400000200007e3013711bc126a8708a324472fdfcf6855cef1f979b0df43475c9568e33000000

image

from node-webdollar.

ader1990 avatar ader1990 commented on August 16, 2024

Perfect, it is the same thing if I do:
atob(Buffer.from(data, 'base64'))

Now, what is a valid hashPrev in hexa for the block[0] or the timestamp?
update: I saw the timestamp: is 1095

from node-webdollar.

ader1990 avatar ader1990 commented on August 16, 2024

The timestamp that I got following the code from:

this.timeStamp = Serialization.deserializeNumber( BufferExtended.substr(buffer, offset, 4) );

is: deserializeNumber(substr(buffer, 0 + 32 + 4 +2+32, 4))
842281008

which is not the same.

This means that either I am doing something wrong (which I do not know), either the code from the repo is wrong.

from node-webdollar.

ibudisteanu avatar ibudisteanu commented on August 16, 2024

Your timestamp is for a date in the year of 1997.

I have uploaded you encoded block and decoded block. Try to obtain the values step by step, decoding hash, nonce, version, hashPrev and then the timestamp. Try to extract the current hash. Check the first image I have uploaded to see the data.

Be sure you have the same data as it was posted by me above.

from node-webdollar.

ibudisteanu avatar ibudisteanu commented on August 16, 2024

my timestamp is offseted by subtracting the Genesis timestamp. You can see the real value in the first screenshot i have uploaded. The timestamp of block[0] should be 1095

from node-webdollar.

ibudisteanu avatar ibudisteanu commented on August 16, 2024

Moreover, 1095 is the 0x447. So you can see that I have spotted 0x447 in my hex data

00007e3013711bc126a8708a324472fdfcf6855cef1f979b0df43475c9568e330000e7240001731d46c131eb6dd4667a96bdc27baf9223bec72c3468dfb6ba52c460e76423a4000004476c1d355b03205412204804e427f9a56de15f10f0c80fc530fecde9a48ae6aede861e9903e5422f7c111358032dfe6ca37aad8bdd5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456000000000a1cfceb215aeac46c0b7eea0d5da9defd927e24504b757e6c3d3702853c9c9901000001731d46c131eb6dd4667a96bdc27baf9223bec72c3468dfb6ba52c460e76423a4

in my opinion, you are doing something wrong

from node-webdollar.

ader1990 avatar ader1990 commented on August 16, 2024

I told you already the encoded/decoded blocks are okay, I want to know how you extract the timestamp 1095 from that, as the code from the repo does not extract correctly.

from node-webdollar.

ader1990 avatar ader1990 commented on August 16, 2024

Basically, what is the math behind choosing for the timestamp an offset? And what are the steps using the primitives from the repo like substring or deserializeNumber and get you to the value: 1095?

from node-webdollar.

ibudisteanu avatar ibudisteanu commented on August 16, 2024

it is simple. I use byte operations.

...60e76423a4000004476c1d355b032...

I extract the bytes, you should get a buffer of 00 00 04 47, then I convert this buffer of 4 bytes into a Number and you will get the 1095 lucky number. Regarding your question, why I have substracted Genesis timestamp as an offset, with the only purpose that all timestamps must be higher than Genesis Timestamp by this way, I am partially solving the Javascript https://en.wikipedia.org/wiki/Year_2038_problem

from node-webdollar.

ibudisteanu avatar ibudisteanu commented on August 16, 2024

The genesis timestamp was set as an appropriate number to the Unix timestamp when I was preparing the new hard fork for main net.

from node-webdollar.

ader1990 avatar ader1990 commented on August 16, 2024

The question is from where do I know the offset? this is not documented and what is the math behind finding it?

from node-webdollar.

ader1990 avatar ader1990 commented on August 16, 2024

I am asking a simple thing, a piece of code that gets you from this "00007..a4" string to the timestamp.

from node-webdollar.

ibudisteanu avatar ibudisteanu commented on August 16, 2024

deserializeBlock(buffer,, offset){

    if (!Buffer.isBuffer(buffer))
        if (typeof buffer === "string")
            buffer = new Buffer(buffer, "hex");

    if (offset === undefined) offset = 0;

    if ( (buffer.length - offset) > consts.SETTINGS.PARAMS.MAX_SIZE.BLOCKS_MAX_SIZE_BYTES )
        throw {message: "Block Size is bigger than the MAX_SIZE.BLOCKS_MAX_SIZE_BYTES", bufferLength: buffer.length };

    try {

        this.hash = BufferExtended.substr(buffer, offset, consts.BLOCKCHAIN.BLOCKS_POW_LENGTH);
        offset += consts.BLOCKCHAIN.BLOCKS_POW_LENGTH;

        this.nonce = Serialization.deserializeNumber( BufferExtended.substr(buffer, offset, consts.BLOCKCHAIN.BLOCKS_NONCE) );
        offset += consts.BLOCKCHAIN.BLOCKS_NONCE;



        this.version = Serialization.deserializeNumber( BufferExtended.substr(buffer, offset, 2) );
        offset += 2;


        this.hashPrev = BufferExtended.substr(buffer, offset, consts.BLOCKCHAIN.BLOCKS_POW_LENGTH);
        offset += consts.BLOCKCHAIN.BLOCKS_POW_LENGTH;


        this.timeStamp = Serialization.deserializeNumber( BufferExtended.substr(buffer, offset, 4) );
        offset += 4;

extracted from the code. If you call this function with the buffer 00007e3013711bc126a8708a324472fdfcf6855cef1f979b0df43475c9568e330000e7240001731d46c131eb6dd4667a96bdc27baf9223bec72c3468dfb6ba52c460e76423a4000004476c1d355b03205412204804e427f9a56de15f10f0c80fc530fecde9a48ae6aede861e9903e5422f7c111358032dfe6ca37aad8bdd5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456000000000a1cfceb215aeac46c0b7eea0d5da9defd927e24504b757e6c3d3702853c9c9901000001731d46c131eb6dd4667a96bdc27baf9223bec72c3468dfb6ba52c460e76423a4 you will get the timestamp.

from node-webdollar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.