Skip to content

Allow to iterate a byte array inside the smart contract#1265

Closed
shargon wants to merge 0 commit intoneo-project:masterfrom
shargon:fix-1172
Closed

Allow to iterate a byte array inside the smart contract#1265
shargon wants to merge 0 commit intoneo-project:masterfrom
shargon:fix-1172

Conversation

@shargon
Copy link
Copy Markdown
Member

@shargon shargon commented Nov 21, 2019

Close #1172
Wait for #1178

This code works if the StackItem is an Array, not a buffer, but I think that this is not the expected behaviour for a c# developer.

public static int TestNext(byte[] a)
        {
            int sum = 0;
            var enumerator = Enumerator<byte>.Create(a);

            while (enumerator.Next())
            {
                sum += enumerator.Value;
            }

            return sum;
        }

@shargon shargon requested a review from erikzhang November 21, 2019 19:08
engine.CurrentContext.EvaluationStack.Push(StackItem.FromInterface(enumerator));
return true;
}
case ByteArray buffer:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be PrimitiveType. Please wait for #1178.

private readonly byte[] array;
private int index = -1;

public BufferWrapper(ByteArray array)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PrimitiveType

@shargon
Copy link
Copy Markdown
Member Author

shargon commented Nov 25, 2019

Moved to #1281

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ByteArray compatible with Enumerator

2 participants