Using Namespace as API

Greetings Everyone,

I am planning to use Namespace to help users integrate my oracle functionality easily in their contracts.

With this code:

Namespace

contract OracleConnector =
    entrypoint createOracle : (bytes(32), int, int) => bool
    entrypoint query: (string) => bytes(32)
    entrypoint canCallBack: () => bool

contract OracleAddressResolver =
    entrypoint getAddress : () => address

namespace Say =
    public function getOracleAddress() : address =
        let ar : OracleAddressResolver = ct_xRAL2ZaqffbTAeQrAunrR8jxdg9YbJvuEnFFJC8g8oW4LJ7Um
        ar.getAddress()
        
contract Boolean =
  record boolean = {
    ok: bool
   }

and

Deriving Contract

include "./Say.aes"
contract MyContract =
  public entrypoint plus() : address =
    Say.getOracleAddress()

I get an error:

Please let me know that is it not possible to inherit other contracts inside the namespace?
Is there any alternative to this?

Thank you.

1 Like
$ ./priv/bin/v4.3.1/aesophia_cli /tmp/MyContract.aes 
Bytecode:
cb_+MVGA6B4Ye+H+uYcJkmNNLdHXz/z0FjOBmcRCo+FyS/CZHUU0sC4mLhh/kTWRB8ANwA3ABoOgj8BAz/+Zy/fMgA3AEcABAMR0EeEMP7QR4QwAjcARwAMAwAMA58CoH3UgO91P+ZiM+Nw/pkFWa+cPpOCMuFYIloQKNBCk1iJAwD8ES3nTmI3AEcAALEvAxFE1kQfEWluaXQRZy/fMhFwbHVzEdBHhDBVLlNheS5nZXRPcmFjbGVBZGRyZXNzgi8AhTQuMy4wAMxVZno=

Can’t reproduce, what version of the compiler do you run?

That said, there is no concept of inheritance in Sophia (yet!) so you shouldn’t expect anything magic to happen :wink:

2 Likes

I will try to use a different compiler version, thank you and sorry for using word inherit. I just meant the above thing :slight_smile: Please do let me know what does we call it.

1 Like

I tried with aeternity/aesophia_http:v4.3.0 and 4.3.2 (latest) images https://hub.docker.com/r/aeternity/aesophia_http/tags?page=1&ordering=last_updated
But they all give me same error, It looks like the docker images are not getting built anymore with new compiler versions.

I saw your pull request (thank you), I will try to use it https://github.com/aeternity/aesophia_http/pull/66

1 Like

Greetings @hanssv.chain,

I tried with 5.0.0 https://hub.docker.com/r/jeevanjotsingh/aesophia_http/tags?page=1&ordering=last_updated

but I am still getting that same error.

Contract '/home/ubuntu/aeternity-projects/oracles/contracts/MyContract.aes has not been compiled'
type_error: Unbound type OracleAddressResolver (at line 3, column 22).

At: Line 3, Column 22

and after the compiler update to 5.0.0, I started to get a new error for this (below line)

let uniq_id : bytes(32) = Crypto.sha3(String.concat(String.concat(Address.to_str(Contract.address), Address.to_str(Call.caller)), Int.to_str(state.reqc[Call.caller])))

The error I got for the above line is:

Contract '/home/ubuntu/aeternity-projects/oracles/contracts/OracleConnector.aes has not been compiled'
type_error: Unbound variable String.concat at line 33, column 48

At: Line 33, Column 48

With 4.3.2 only the 1st error remains, for the error “Unbound variable String.concat…”, It Does not come and the file compiles successfully.

Contract '/home/ubuntu/aeternity-projects/oracles/contracts/OracleConnector.aes has been successfully compiled'
Contract bytecode: "cb_+QSnRgOgW1zqrVYL/ol6ohXZmQj9h1JJ5wdSBatGPenlEVz++FPAuQR5uQO0/gcrv+0ENwOXQAcHRwMaCgCCLxoCggAMA6+CAAEAPwcOAgwMA6+CAAEAPwYDBCAABwwI+wPBVGhpcyB0eXBlIG9mIG9yYWNsZSB3YXMgYWxyZWFkeSByZWdpc3RlcmVkIG9uY2UuDAN3DAN3DAEERPwjAgIAAl4AZgBOCJ8BAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgwCCAwDSU5ldyBvcmFjbGUgY3JlYXRlZET8IwgEAgQCAxFlpeAPDwJvgibPAQIIKxgAAET8IwACAgIGAwT+CcGfqQA3AEcAXgAA/kTWRB8ANwA3ABoOBi8AVQAtyogG/xoOgi8AGg6ELwAaDoYvAAEDP/5F2ptTBDcAB1MAAP5lpeAPAjcBhwI3BEcAl0AHdzcCRwN3NwAIPQACBEY2AAAARjYCAAJGNgQABEY2BgAGZAKuBp8BgecZeXJfGotN0K3b2GLMq6ZvPTwCkyci0BFPW/+enQMDAAIEAQM/RjYAAABGNgIAAmIuAp8Bgd52yx3uBbxQpiTABQ5Z63sAeG/1+MikB7sh0B2tH5L/AAEDP/6BHC84ADcAB1MAAP6JFi3FADcBd5dAVQB7AAcMBPsDcU9ubHkgYSBjb250cmFjdCBjYW4gY2FsbCBpdCFVAgQaCgaELyoIhAQMA6+CAAEAPwcOCBIMA6+CAAEAPwYDCCAABwwQDAM/BgMMDwJvgibPGgoWhFUAKwgWEFUALQqEhBoKIoRVACsIIjsAVQA8AF4APAA6ADoAGwIkVQAMAiRYAAwBAET8IwgEAAgCAxFlpeAPDwJvgibPAQIkVQAtyoSEAAwDPwYDDCsoBgRE/CMAAgICBgMI/qluY0kANwFHABcaCgCIVQArCAAgMP8HDAT7A41Pbmx5IG93bmVycyBjYW4gZG8gdGhpcyB0cmFuc2FjdGlvbi3ahoYA/wED//6v0X2YADcCRwAHNwAaCgCIVQArCAAgMP8HDAT7A41Pbmx5IG93bmVycyBjYW4gZG8gdGhpcyB0cmFuc2FjdGlvbmUFAAIBAz/+1ABKMwA3ABdVAgAaCgKGLyoEhgAMA6+CAAEAPwcOBAwMA6+CAAEAPwYDBCAABwwKBgMIGgoKhlUAKwgKIDD/APsDnU9ubHkgYWNjZXB0ZWQgYWRkcmVzcyBjYW4gc2VuZCBjYWxsYmFjaysoAgBE/CMAAgICBgMEuL0vChEHK7/tMWNyZWF0ZU9yYWNsZREJwZ+pQWNvbnRyYWN0X2FkZHJlc3MRRNZEHxFpbml0EUXam1MxYWNjZXB0QXNzZXRzEWWl4A8tQ2hhaW4uZXZlbnQRgRwvOGVnZXRDdXJyZW50Q29udHJhY3RCYWxhbmNlEYkWLcUVcXVlcnkRqW5jSUlhZGRDYWxsQmFja0FkZHJlc3MRr9F9mDV3aXRoZHJhd0Z1bmRzEdQASjMtY2FuQ2FsbEJhY2uCLwCFNC4zLjAA4fTd5w=="
1 Like

Did you read the release notes for 5.0.0?
Literally the first line says:
"A new and improved String standard library has been added. Use it by include "String.aes" .

That should solve the “new” “issue” you had…

As for the rest, I was using the latest released command line compiler (I haven’t really understood the fascination for having the compiler in a web server :sweat_smile:) namely v4.3.1. I took the code labeled Namespace and put it in /tmp/Say.aes and the code labeled Deriving contract and put it in /tmp/MyContract.aes and it compiles just fine.

1 Like

Thank you @hanssv.chain
Sorry, I didn’t saw release notes.

For the newest issue (String issue), In the end, The OracleConnector contract compiles successfully after I put include "String.aes". I just get this one line above all contract bytecodes:
File to include 'String.aes' not found. Check your path or it is from Sophia default library .

For the old issue
On every try, I keep getting:

Contract '/home/ubuntu/aeternity-projects/oracles/contracts/MyContract.aes has not been compiled'
type_error: Unbound type OracleAddressResolver (at line 3, column 18).

At: Line 3, Column 18

I am not sure where should I look to see what causing this.

My directory structure (libs is just there as empty folder, I will put libraries there, Later)

image

I don’t think I can help you any further, I am afraid. As far as I can tell, the compiler is working. Main problem seems to be whatever you have in between the compiler and your code, and that is outside my area of expertise.

Also note that v5.0.0 isn’t fully released in cli or http mode yet, I’ll check that String is available before finishing that.

1 Like

Thank you @hanssv.chain
Your help is really appreciated. I will try to ask about my issue in today’s session and try to figure out some solution :slight_smile:

I know the problem might be currently a little out from your area of expertise but I just like to share that, I tried with remote compiler just now https://compiler.aepps.com and still the same issues.

Again the problem is not the compiler but what you send it. It can’t be what you have presented here because that compiles just fine. EVEN WITH THE HTTP-COMPILER:

$ Say="contract OracleConnector =
    entrypoint createOracle : (bytes(32), int, int) => bool
    entrypoint query: (string) => bytes(32)
    entrypoint canCallBack: () => bool

contract OracleAddressResolver =
    entrypoint getAddress : () => address

namespace Say =
    public function getOracleAddress() : address =
        let ar : OracleAddressResolver = ct_xRAL2ZaqffbTAeQrAunrR8jxdg9YbJvuEnFFJC8g8oW4LJ7Um
        ar.getAddress()
        
contract Boolean =
  record boolean = {
    ok: bool
   }"
$ MyContract="include \\\"./Say.aes\\\"
contract MyContract =
  public entrypoint plus() : address =
    Say.getOracleAddress()"
$ FILE_SYS="{\"./Say.aes\":\"$Say\"}"
$ curl -H "Content-Type: application/json" -d "{\"code\":\"$MyContract\",\"options\":{\"backend\":\"fate\", \"file_system\":$FILE_SYS}}" -X POST https://compiler.aepps.com/compile
{"bytecode":"cb_+MVGA6BbuBJDJkdk9p4K2LZem5GB+2SCsEy9oU6+tFtIcSeSHsC4mLhh/kTWRB8ANwA3ABoOgj8BAz/+Zy/fMgA3AEcABAMR0EeEMP7QR4QwAjcARwAMAwAMA58CoH3UgO91P+ZiM+Nw/pkFWa+cPpOCMuFYIloQKNBCk1iJAwD8ES3nTmI3AEcAALEvAxFE1kQfEWluaXQRZy/fMhFwbHVzEdBHhDBVLlNheS5nZXRPcmFjbGVBZGRyZXNzgi8AhTQuMS4wAHTetj0="}
3 Likes

Greetings Hans,

So far My progress looks like this:
I found the regexp that matches and sends back the contract code to further send it to the compiler server https://github.com/aeternity/aepp-aeproject-js/blob/2c015c5c23205ee0fd90e180bf649cb71f79b8a9/packages/aeproject-utils/utils/aeproject-utils.js#L10

let rgx = /^include\s+\"([\d\w\/\.\-\_]+)\"/gmi;
let dependencyPathRgx = /"([\d\w\/\.\-\_]+)\"/gmi;
const mainContractsPathRgx = /.*\//g;
let match;

it looks like the file system misses its above two contracts declaration OracleConnector and OracleAddressResolver when logging the result of MyContract

Below is the body of my contract https://github.com/aeternity/aepp-aeproject-js/blob/2c015c5c23205ee0fd90e180bf649cb71f79b8a9/packages/aeproject-utils/utils/aeproject-utils.js#L216

the options part is at line 215 (Above the assigning body) formed by getDependencies https://github.com/aeternity/aepp-aeproject-js/blob/2c015c5c23205ee0fd90e180bf649cb71f79b8a9/packages/aeproject-utils/utils/aeproject-utils.js#L235


{
  code: 'include "./libs/Say.aes"\n' +
    'contract MyContract =\n' +
    '    public entrypoint plus() : address =\n' +
    '      Say.getOracleAddress()\n' +
    '        ',
  options: {
    file_system: {
      './libs/Say.aes': 'namespace Say =\n' +
        '    public function getOracleAddress() : address =\n' +
        '        let ar : OracleAddressResolver = ct_xRAL2ZaqffbTAeQrAunrR8jxdg9YbJvuEnFFJC8g8oW4LJ7Um\n' +
        '        ar.getAddress()\n' +
        '        \n' +
        '\n' +
        'contract Boolean =\n' +
        '  record boolean = {\n' +
        '    ok: bool\n' +
        '   }'
    }
  }
}

While trying, I guessed that if it was reading dependency (from getDependencies) it start from the word namespace instead of the file beginning, (Why ? I am sorry but due to hackathon period I am in hurry to complete my submission so will not investigate further on, maybe later if I get some time). So i created a dummy namespace on top of the file so it can work inside the aeproject till we find the fix.

Before ====>

dependencies ===>>
{
  './libs/Say.aes': 'namespace Say =\n' +
    '    public function getOracleAddress() : address =\n' +
    '        let ar : OracleAddressResolver = ct_xRAL2ZaqffbTAeQrAunrR8jxdg9YbJvuEnFFJC8g8oW4LJ7Um\n' +
    '        ar.getAddress()\n' +
    '        \n' +
    '\n' +
    'contract Boolean =\n' +
    '  record boolean = {\n' +
    '    ok: bool\n' +
    '   }'
}

After ====>

dependencies ===>>
{
  './libs/Say.aes': 'namespace Saydummy =\n' +
    '    public function dummy() : bool =\n' +
    '        true\n' +
    'contract OracleConnector =\n' +
    '    entrypoint createOracle : (bytes(32), int, int) => bool\n' +
    '    entrypoint query: (string) => bytes(32)\n' +
    '    entrypoint canCallBack: () => bool\n' +
    '\n' +
    'contract OracleAddressResolver =\n' +
    '    entrypoint getAddress : () => address\n' +
    'namespace Say =\n' +
    '    public function getOracleAddress() : address =\n' +
    '        let ar : OracleAddressResolver = ct_xRAL2ZaqffbTAeQrAunrR8jxdg9YbJvuEnFFJC8g8oW4LJ7Um\n' +
    '        ar.getAddress()\n' +
    '        \n' +
    '\n' +
    'contract Boolean =\n' +
    '  record boolean = {\n' +
    '    ok: bool\n' +
    '   }'
}

Thank you @hanssv.chain for helping it giving the idea of possible cause and @ae-omar for bringing it in the session and @nikitafuchs.chain for giving an idea of possible cause as regex.

Compiled MyContract.aes from aeproject :slight_smile:

Contract '/home/ubuntu/aeternity-projects/oracles/contracts/MyContract.aes has been successfully compiled'
Contract bytecode: "cb_+MVGA6C9SmcMAIbrlS39WZddoIu1//P1XLfHgvB0jLrRDQYBO8C4mLhh/kTWRB8ANwA3ABoOgj8BAz/+Zy/fMgA3AEcABAMR0EeEMP7QR4QwAjcARwAMAwAMA58CoH3UgO91P+ZiM+Nw/pkFWa+cPpOCMuFYIloQKNBCk1iJAwD8ES3nTmI3AEcAALEvAxFE1kQfEWluaXQRZy/fMhFwbHVzEdBHhDBVLlNheS5nZXRPcmFjbGVBZGRyZXNzgi8AhTQuMS4wAObWR5M="
1 Like

@hanssv.chain
If you like to know what was the issue, You can check it out here:- https://github.com/aeternity/aepp-aeproject-js/issues/372

1 Like