Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow borsh-serialized contract fn arguments #426

Merged
merged 2 commits into from
Oct 8, 2020

Conversation

chadoh
Copy link
Contributor

@chadoh chadoh commented Oct 7, 2020

Let's say you have a contract object instantiated in your code, and the contract it wraps has an add_person function which receives a borsh-serialized struct. The following code now works:

import { serialize } from 'near-api-js/lib/utils/serialize'

class Person {
  constructor (proof) {
    Object.assign(this, proof)
  }
}

const personSchema = new Map([
  [Person, {
    kind: 'struct',
    fields: [
      ['age', 'u64'],
      ['name', 'String'],
    ]
  }]
])

const person = new Person({ age: 33, name: 'Jesus' })

contract.add_person(serialize(personSchema, person))

@chadoh chadoh requested a review from vgrichina October 7, 2020 00:23
@chadoh chadoh force-pushed the allow-borsh-serialization branch from b929507 to ed2147b Compare October 7, 2020 00:24
src/contract.ts Outdated Show resolved Hide resolved
@vgrichina
Copy link
Contributor

@chadoh need to fix test failures

chadoh added 2 commits October 7, 2020 20:00
Let's say you have a `contract` object instantiated in your code, and
the contract it wraps has an `add_person` function which receives a
borsh-serialized struct. The following code now works:

    import { serialize } from 'near-api-js/lib/utils/serialize'

    class Person {
      constructor (proof) {
        Object.assign(this, proof)
      }
    }

    const personSchema = new Map([
      [Person, {
        kind: 'struct',
        fields: [
          ['age', 'u64'],
          ['name', 'String'],
        ]
      }]
    ])

    const person = new Person({ age: 33, name: 'Jesus' })

    contract.add_person(serialize(personSchema, person))
add stronger typing to `nameFunction`
@chadoh chadoh force-pushed the allow-borsh-serialization branch from c3c69c3 to c7dc8a9 Compare October 8, 2020 00:01
@chadoh chadoh merged commit 41be9de into master Oct 8, 2020
@chadoh chadoh deleted the allow-borsh-serialization branch October 8, 2020 01:03
@chadoh chadoh restored the allow-borsh-serialization branch October 8, 2020 01:03
@chadoh
Copy link
Contributor Author

chadoh commented Oct 8, 2020

@vgrichina merged; could you cut a release?

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.

2 participants